Chartjs-Is it possible to add more attributes to segement in a Doughnut chart of Chart JS?

1👍

Just add them to your data

var data = [
    {
        value: 300,
        color:"#F7464A",
        highlight: "#FF5A5E",
        label: "Red",
        extra: 1
    },
    ...

and once the chart is created, add it to the chart elements

...
var myChart = new Chart(ctx).Pie(data);

myChart.segments.forEach(function(segment, i){
   segment.extra = data[i].extra
})

and the access it using the element

canvas.onclick = function(evt){
    var activeSegment = myChart.getSegmentsAtEvent(evt);
    alert(activeSegment[0].extra)
};

Just click on a sector to see it in action here

Fiddle – http://jsfiddle.net/aswfsyxw/

Leave a comment