Wie hinzufügen von OnClick-Event auf den Etiketten in Chart.js v2.0?

Suche nach einer Methode zum hinzufügen von onClick-Griff auf den "label" - element in chartjs 2.0
Als unter Verwendung der folgenden Verfahren zurück "undifined" in der Konsole.melden Sie, wenn ein Klick auf eines der label-Attribute in Char.js V2.0 RadarChart.

var data = {
    //below line is the labels 
    labels: ["Eating", "Drinking", "Sleeping", "Designing", "Coding", "Cycling", "Running"],
    datasets: [
        {
            label: "My First dataset", //this only shows as legend, not label.

            backgroundColor: "rgba(179,181,198,0.2)",
            borderColor: "rgba(179,181,198,1)",
            pointBackgroundColor: "rgba(179,181,198,1)",
            pointBorderColor: "#fff",
            pointHoverBackgroundColor: "#fff",
            pointHoverBorderColor: "rgba(179,181,198,1)",
            data: [65, 59, 90, 81, 56, 55, 40]
        },
       ....

JS:

//Below is how to OnClick on chart points in chart.js V2, 
//However, it didn't apply to labels, will return "undifined" .   
$('#ChartV2').click(function(e) {
                var activePoints = myRadarChart.getElementsAtEvent(e);                  
                var firstPoint = activePoints[0];
                console.log(firstPoint);
                if (firstPoint !== undefined){
                   alert(firstPoint._index);                        
                }
 });

InformationsquelleAutor infiniteloop | 2016-05-04
Schreibe einen Kommentar