문제

I want to bind a function to a click event for a data point in Highcharts. Clicking a data point has to call a function, but the arguments to the function are dynamic (i.e. there are several graphs drawn, and the "car" variable is generated anew for each graph).

How to bind "getCarDate()" to click event properly? This does not work (car simply holds the last assigned value instead of a different value for each plot):

                         plotOptions: {
                            series: {
                                cursor: 'pointer',
                                point: {
                                    events: {
                                        click: function (e) {
                                            getCarDate(this.x, car)
                                        }
                                    }
                                },
                                marker: {
                                    lineWidth: 1
                                }
                            }
                        },
도움이 되었습니까?

해결책

One trick you could use here would be to stash the value into the Highcharts options:

$('#container'+i).highcharts({

    myData: car,

    plotOptions: {
        series: {
            cursor: 'pointer',
            point:{                 
                events: {
                    click: function(event) {     
                       alert(this.series.chart.userOptions.myData);
                    }
                }
           }
        }
    },

Here's a fiddle.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top