Sankey图的EdgeLabel无法显示具体数值
BpointA opened this issue · comments
问题
在绘制桑基图时,需要在每条边上体现具体的数值,但是无法通过formatter实现。
js中正确的formatter应该是{c},但pyecharts中输入{c}显示的是undefined。
运行环境(系统环境及 pyecharts 版本)
python 3.10.8
pyecharts 2.0.4
代码及截图
add中代码如下:
edge_label_opt=opts.LabelOpts(position="right",
font_size=12,
formatter='{c}',
),
以下是在echarts(js)中使用formatter={c}的结果
以下是在pyecharts(js)中使用formatter={c}的结果
@BpointA 试下这个代码
nodes = [
{"name": "category1"},
{"name": "category2"},
{"name": "category3"},
{"name": "category4"},
{"name": "category5"},
{"name": "category6"},
]
links = [
{"source": "category1", "target": "category2", "value": 10},
{"source": "category2", "target": "category3", "value": 15},
{"source": "category3", "target": "category4", "value": 20},
{"source": "category5", "target": "category6", "value": 25},
]
c = (
Sankey()
.add(
"sankey",
nodes,
links,
edge_label_opt=opts.LabelOpts(is_show=True),
linestyle_opt=opts.LineStyleOpts(opacity=0.2, curve=0.5, color="source"),
label_opts=opts.LabelOpts(position="right"),
)
.set_global_opts(title_opts=opts.TitleOpts(title="Sankey-基本示例"))
)
@BpointA 试下这个代码
nodes = [ {"name": "category1"}, {"name": "category2"}, {"name": "category3"}, {"name": "category4"}, {"name": "category5"}, {"name": "category6"}, ] links = [ {"source": "category1", "target": "category2", "value": 10}, {"source": "category2", "target": "category3", "value": 15}, {"source": "category3", "target": "category4", "value": 20}, {"source": "category5", "target": "category6", "value": 25}, ] c = ( Sankey() .add( "sankey", nodes, links, edge_label_opt=opts.LabelOpts(is_show=True), linestyle_opt=opts.LineStyleOpts(opacity=0.2, curve=0.5, color="source"), label_opts=opts.LabelOpts(position="right"), ) .set_global_opts(title_opts=opts.TitleOpts(title="Sankey-基本示例")) )
可以了,感谢!
我排查了一下,是我在label_opt中设置了格式={b},去掉之后就好了。