HIghcharts, Selecting a second Point within the Po

2019-08-28 20:26发布

$(function () {
  var chart = {
    plotOptions: {
      series: {
        point: {
          'events' : {
            select: function(){
              var pId = this.series.data.indexOf(this);

              var chart1 = $('#container').highcharts();
              var chart2 = $('#container2').highcharts();


        //These are the extra selects I want to happen
        //chart1.series[0].data[5].select(true,true);
        //chart2.series[0].data[pId].select();

            }
          }
        }
      }
    },
    series: [{
      data: [29.9, 71.5, 106.4,
             129.2, 144.0, 176.0,
             135.6, 148.5, 216.4,
             194.1, 95.6, 54.4]
    }] 
  };
  $('#container').highcharts(chart);
  $('#container2').highcharts(chart);

  var chart = $('#container').highcharts();

  i = 0;
  $('#button').click(function() {
    if (i == chart.series[0].data.length) 
    i = 0; 

    chart.series[0].data[i].select();
    i++;
  });


});

http://jsfiddle.net/rphne/

http://jsfiddle.net/rphne/5/

You can see what I'm trying to achieve there. Essentially, I want to select a point on the same graph, as well as a point on a second graph after the select event occurs.

In the example above, it should select the same point on chart 1 and chart 2, as well as chart1 selecting a second point on itself.

I figured just doing a .Select(true,true) would accumulate, however this fails when done within the select event. I believe I'm looking for a callback event kind of thing, so that after the Select has successfully completed, I can then do my extra selects.

Any advice?

1条回答
啃猪蹄的小仙女
2楼-- · 2019-08-28 20:53

In the button action you select only one point from one chart, because use use chart.series[0].data[i].select(); in first object. Only what you need is add the same action for second chart.

http://jsfiddle.net/rphne/1/

EDIT: You can also use setState() function to sychronise both charts. http://jsfiddle.net/rphne/6/

查看更多
登录 后发表回答