Chartist-js: Pie Chart (donut) with Label

Created on 4 Sep 2015  路  4Comments  路  Source: gionkunz/chartist-js

Hi,

I want to ask if it is possible to the Label with the percentage value. I have try without success. Thanks.

var data = {
labels:['mon','tue','wed'],
series: [5, 3, 4]
};

var sum = function(a, b) { return a + b };

new Chartist.Pie('.ct-chart', data, {
labelInterpolationFnc: function(value) {
return Math.round(value / data.series.reduce(sum) * 100) + '%';
}
});

Most helpful comment

did you try this?

new Chartist.Pie('.ct-chart', data, {
    labelInterpolationFnc: function(label, index) {
        return label + " " + Math.round(data.series[index] / data.series.reduce(sum) * 100) + '%';
    }
});

All 4 comments

If you want the value to be passed to labelInterpolationFnc you should not specify any labels.

Hi,

What I want to achieve is for the label on the pie chart for example to show "mon 42%" instead of the present code which only show the "42%". Thanks.

did you try this?

new Chartist.Pie('.ct-chart', data, {
    labelInterpolationFnc: function(label, index) {
        return label + " " + Math.round(data.series[index] / data.series.reduce(sum) * 100) + '%';
    }
});

Closing this issue, please re-open if needed

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gsklee picture gsklee  路  4Comments

eddr picture eddr  路  3Comments

ShlomoRosenheimer picture ShlomoRosenheimer  路  3Comments

LandonSchropp picture LandonSchropp  路  3Comments

FabienPapet picture FabienPapet  路  4Comments