比如在零售业,同时查看销售业绩和目标达成:
原理为DAX+HTML,图表度量值:
M.P.柱形图环形图 =
VAR MaxSales = MAXX(ALLSELECTED('店铺资料'[城市]), [M.销售业绩])
VAR DonutChart =
"<svg width='60' height='60' id='wujunmin' viewBox='0 0 42 42'>
<circle cx='21' cy='21' r='15' fill='none' stroke='#EAEAEA' stroke-width='4'/>
<circle cx='21' cy='21' r='15' fill='none' stroke='#FF6B6B' stroke-width='4'
stroke-linecap='round' stroke-dasharray='" & [M.业绩达成率] * 100 & ",100' transform='rotate(-90 21 21)'/>
<text x='21' y='26' font-family='Arial' font-size='10' font-weight='600' text-anchor='middle' fill='#333'>" &
FORMAT( [M.业绩达成率], "0%") & "</text>
</svg>"
VAR BarChart =
"<div style='display: flex; flex-direction: column; align-items: center; width: 100%; gap: 10px; padding: 12px; background: white; border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,0.05);'>
<div style='height: 220px; width: 100%; position: relative; display: flex; align-items: flex-end; background: white; border: 1px solid #EEE; border-radius: 4px;'>
<div style='width: 100%; height: " & [M.销售业绩] / MaxSales * 100 & "%; background: #444; position: relative; border-radius: 4px 4px 0 0; transition: height 0.3s ease;'>
<div style='position: absolute; top: 2px; left: 50%; transform: translateX(-50%);
color: snow; font-family: Arial; font-size: 12px; font-weight: 700; white-space: nowrap;'>
" & FORMAT([M.销售业绩], "#,##0") & "
</div>
</div>
</div>
<div style='font-family: Arial; font-weight: 600; font-size: 14px; color: #444;'>
" & SELECTEDVALUE('店铺资料'[城市]) & "
</div>
<div style='margin-top: 8px;'>" & DonutChart & "</div>
</div>"
RETURN BarChart
度量值在HTML Content视觉对象使用:
横向的版本:
更多Power BI SVG、HTML可视化可以访问我的github主页:
https://junminwu.github.io/
wujunmin