Screen diagrams connecting a scatter plot and a pie chart with one legend

I am trying to connect two different diagrams (scatter and pie chart) using the same legend. When printing to the console, it seems that javascript is extracting the correct data from the correct pie chart. It simply does not connect to the legend of the scatterplot. I also tried what these answers suggested: HighCharts: One Legend, Two Charts and Multiple Pie Charts in the same chart with HighCharts

I use this code in my series. Scatter plot 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 is my fiddle

+4
source share
1

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)

            }

          }
        }
      }
    }
  }
},

Forked Fiddle

this.options.name === series.name

this.options.name === series_arr[series].name

setVisible()

+1

Source: https://habr.com/ru/post/1680463/


All Articles