[英]Highcharts connecting scatter chart and pie chart with single legend
I'm trying to connect two different charts (a scatter and a pie chart) using the same legend. 我正在尝试使用相同的图例连接两个不同的图表(散点图和饼图)。 Upon printing to console, it seems like javascript is fetching the correct data of the correct pie chart.
在打印到控制台后,似乎javascript正在获取正确的饼图的正确数据。 It just won't connect to the scatter chart legend.
它只是不会连接到散点图图例。 I tried what these answers suggested too: HighCharts: One Legend, Two Charts and Multiple pie-charts in the same chart with HighCharts
我也尝试了以下答案的建议: HighCharts:一个图例,两个图表和带有HighCharts的同一图表中的多个饼图
I'm using this code in my series.events of the scatter chart: 我在散点图的series.events中使用此代码:
events: {
legendItemClick: function (event) {
console.log(this.options.name);
var donut = $('#pie_chart').highcharts(),
series_arr = donut.series[0].data;
console.log(series_arr);
for (series in series_arr) {
if (this.options.name === series.name) {
if (this.visible) {
series.visible = true;
} else {
series.visible = false;
}
}
}
}
}
Am I missing something here? 我在这里想念什么吗? Here is my fiddle
这是我的小提琴
plotOptions
will be as plotOptions
将为
plotOptions: {
column: {
stacking: ''
},
series: {
pointPadding: 0.2,
borderWidth: 0,
dataLabels: {
//enabled: false
},
events: {
legendItemClick: function(event) {
console.log(this.options.name);
var donut = $('#pie_chart').highcharts(),
series_arr = donut.series[0].data;
//console.log(series_arr);
for (series in series_arr) {
if (this.options.name === series_arr[series].name) {
if (this.visible) {
series_arr[series].setVisible(false);
} else {
series_arr[series].setVisible(true)
}
}
}
}
}
}
},
Error is 错误是
this.options.name === series.name
and it will be 它将是
this.options.name === series_arr[series].name
and use setVisible()
to toggle 并使用
setVisible()
进行切换
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.