Chartjs-How to set label in dataPoints chart on javascript?

0👍

you’ll have add the loop outside options, store result inside the variable then use the variable inside options as shown below.

I’ve stored in dataPoints variable.

var dataPoints = [];

for (var i = 0; i <arrchartdata.length ; i++) {
    console.log(arrchartdata[i].MenuName);
    dataPoints.push({label : arrchartdata[i].MenuName});
}

var options = {
    animationEnabled: true,
    title: {
        text: "GDP Growth Rate - 2016"
    },
    axisY: {
        title: "Growth Rate (in %)",
        suffix: "%",
        includeZero: false
    },
    axisX: {
        title: "Countries"
    },
    data: [{
        type: "column",
        yValueFormatString: "#,##0.0#"%"",
        dataPoints: dataPoints
    }]
};
$("#chartContainer").CanvasJSChart(options);

}
</script>

Leave a comment