又是美好的一天, 熟悉power bi 或者在日常工作有应用过该工具的小伙伴应该都遇到过以下场景,业务用户不知道从哪里搞来一张图对你说想要一样的效果, 你看了眼图片长这个样子.
在你的记忆里,power bi 的柱形图虽然带有边框添加,但是目前还不可以改变柱形图顶部的圆角弧度。
看来今天又要辛苦自己写代码实现了, 你想起上次用Vega实现的渐变色柱形图, 既然能实现渐变那么应该也可以圆角吧?
选中deneb 自定义插件,并任意拖动一个数据到X轴,打开自定义插件的代码编辑页面
在你的辛苦研究和百度大法加持下,最终你实现了业务想要的效果,在业务眼中形象又高大了
为了让大家夸你,你决定把源代码也贴出来!
{ "$schema": "vega.github.io/schema/vega…", "width": 400, "height": 200, "padding": 5,
"data": [ { "name": "table", "values": [ {"category": "A", "amount": 28}, {"category": "B", "amount": 55}, {"category": "C", "amount": 43}, {"category": "D", "amount": 91}, {"category": "E", "amount": 81}, {"category": "F", "amount": 53}, {"category": "G", "amount": 19}, {"category": "H", "amount": 87} ] } ],
"scales": [ { "name": "xscale", "type": "band", "domain": {"data": "table", "field": "category"}, "range": "width", "padding": 0.05, "round": true }, { "name": "yscale", "domain": {"data": "table", "field": "amount"}, "nice": true, "range": "height" } ],
"axes": [ {"orient": "bottom", "scale": "xscale"}, {"orient": "left", "scale": "yscale"} ],
"marks": [ { "type": "rect", "from": {"data": "table"}, "encode": { "enter": { "x": {"scale": "xscale", "field": "category","offset": {"scale": "xscale", "band": 0.35}}, "width": {"scale": "xscale", "band": 0.25}, "y": {"scale": "yscale", "field": "amount"}, "y2": {"scale": "yscale", "value": 0}, "cornerRadiusTopLeft": {"value": 20}, "cornerRadiusTopRight": {"value": 20}, "fill": {"value": "steelblue"} }, "update": { "fillOpacity": {"value": 1} } }, "tooltip": { "signal": "{'Category': datum.category, 'Amount': datum.amount}" } } ] }
关注队长, 持续分享power bi 小知识~