效果如下图所示,条形图用来展示绝对值指标,环形图展示指标和目标对比的进度。
实现方式是SVG/HTML组合。HTML Content视觉对象如下拖拽字段:
图表度量值为:
M.P.环形图条形图 =
VAR MaxSales = MAXX(ALLSELECTED('店铺资料'[城市]), [M.销售业绩])
VAR SalesPercentage = [M.销售业绩] / MaxSales * 100
VAR AchievementRate = [M.业绩达成率]
VAR CityName = SELECTEDVALUE('店铺资料'[城市])
VAR SalesFormatted = FORMAT([M.销售业绩], "#,#")
VAR DonutChart =
"<svg width='50' height='50' viewBox='0 0 42 42'>
<circle cx='21' cy='21' r='15' fill='none' stroke='lightgrey' stroke-width='4'/>
<circle cx='21' cy='21' r='15' fill='none' stroke='#2196F3' stroke-width='4'
stroke-linecap='round' stroke-dasharray='" & AchievementRate * 100 & ",100' transform='rotate(-90 21 21)'/>
<text x='21' y='26' font-family='Arial' font-size='10' text-anchor='middle' fill='#333'>" &
FORMAT(AchievementRate, "0%") & "</text>
</svg>"
--公众号wujunmin
VAR BarChart =
"<div style='display: flex; align-items: center; width: 100%; gap: 10px;'>
<div style='flex-shrink: 0;'>" & DonutChart & "</div>
<div style='flex-grow: 1; position: relative;'>
<div style='height: 30px; background: #f0f0f0; border-radius: 15px; overflow: hidden;'>
<div style='height: 100%; width: " & SalesPercentage & "%; background: linear-gradient(90deg, #2196F3, #64B5F6);
border-radius: 15px 0 0 15px; display: flex; align-items: center; padding-left: 15px;
color: white; font-family: Arial; font-weight: bold; font-size: 15px;'>
" & CityName & " " & SalesFormatted & "
</div>
</div>
</div>
</div>"
RETURN BarChart
度量值中的前五个var换成你模型中的数据即可复用。把度量值扔给DeepSeek可以随意修改样式:
这种SVG+HTML组合图的实现方案其实不够简洁。更优的方案是内置表格使用纯SVG,表格可以新增列,因此图表可以不停地横向扩充。
这里我把它分享出来是为了拓展可能性,有一天也许会在另外的场景发挥它的用处。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有