Highcharts为waterwall和stack柱状图创建图例



Highcharts新手,需要制作瀑布和堆栈柱状图,如所附图像所示。我已经完成了图表,但无法获得堆栈列的图例。

https://jsfiddle.net/b9vLxoua/Here is the chart code

所需图表,图例突出显示

请帮忙。

您可以在渲染回调上使用SVERender工具创建自定义图例。

演示:https://jsfiddle.net/BlackLabel/qhr6nsw9/

render() {
let chart = this,
colors = ['#003975', '#F9BD50', '#3FA27E']
chart.series[1].points.forEach((p,i) => {
if (p.category === 0) {
if (p.customRect) {
p.customRect.destroy();
}
p.customRect = chart.renderer.rect(chart.plotSizeX + chart.plotLeft + 10, 100 + i * 50, 20, 20, 5)
.attr({
fill: colors[i],
zIndex: 3
})
.add();
if (p.customText) {
p.customText.destroy();
}   
p.customText = chart.renderer.label(p.t, chart.plotSizeX + chart.plotLeft + 40, 100 + i * 50).add()
}
})
}

API:https://api.highcharts.com/class-reference/Highcharts.SVGRenderer#label

API:https://api.highcharts.com/highcharts/chart.events.render

最新更新