简体   繁体   中英

Highcharts series click event not firing on first click

I am working with highcharts where I want to draw a spline graph and I am trying to add series dynamically. I have attached click event to series but I am surprised of that its not firing on first click but on subsequent clicks.

Following is my code.

analyticChart.chart.series.splice(dataset.id,0,{
    'data':dataset.data,
    'name':dataset.label,
    'type': 'spline',
    'id':dataset.id+'',
    'yAxis': dataset.id,
    'color': dataset.pointColor,
    'visible':true,
    'marker' : {
        enabled : true,
        radius : 4
    },
    'states': {
        'hover': {
             enabled: false
        }
    },
    'events': {
        click: function (event) {
             console.log("Hello.. mike testing...!!");
             lineChartDatasetClick(datasetList,dataset,index,analyticChart);
        },
        legendItemClick: function (event) {
            try{
                var id = event.target.options.id;
                for(var i=0;i<analyticChart.chart.series.length;i++){ 
                    if(parseInt(id) == parseInt(analyticChart.chart.series[i].id)){
                        if(analyticChart.chart.series[i].visible){
                            analyticChart.chart.series[i].visible = false;
                            analyticChart.chart.options.yAxis[i].labels.enabled = false;
                            analyticChart.chart.options.yAxis[i].lineColor = "transparent";
                        }else{
                             analyticChart.chart.series[i].visible = true;
                             analyticChart.chart.options.yAxis[i].labels.enabled = true;
                             analyticChart.chart.options.yAxis[i].lineColor = analyticChart.chart.series[i].color;
                        }
                        $rootScope.$apply();
                    }
                }
            }catch(e){
                console.log('error in legend ');
            }   
        }
    }
});

please help to find out its solution.

Thank you

I know I am late to this. I have had a similar situation and I found out that we need to set a kdNow option to true in plotOptions series.

plotOptions: {
  series: {
   kdNow: true
 }
}

This made the first click to work more information for this can be found at https://github.com/highcharts/highcharts/issues/6817

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM