You must save the array containing your labels and use labelInterpolationFncwith two parameters to get the index and use it to get the corresponding label with a percentage:
var animals = ['Dog','Cat','Cow','Snake'];
var data = {
series: [5, 3, 4]
};
var sum = function(a, b) { return a + b };
new Chartist.Pie('.ct-chart', data, {
labelInterpolationFnc: function(value, idx) {
var percentage = Math.round(value / data.series.reduce(sum) * 100) + '%';
return animals[idx] + ' ' + percentage;
}
});
Please note that we should not use labels(only a series) in your data array, otherwise the value parameter in labelInterpolationFncwill be filled with a label instead of a value, so we could not calculate the percentage.
source
share