I have pie chart with custom label and percentage. Issue is Label and percentage appears in same line. I need to break percentage and label into two lines. Label percentage
I have try <br>
and \n
but did not work. Please help
var names = ['', 'Home Loans', 'Auto Loans'];
var data = {
series: [3, 5, 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 names[idx] + '\n' + percentage;
}
});
<link href="https://cdnjs.cloudflare.com/ajax/libs/chartist/0.11.0/chartist.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/chartist/0.11.0/chartist.min.js"></script>
<div class="ct-chart"></div>