I'm trying to make percentage show on my graph. Currently, there's a plugin called ChartJS-Plugin-Labels which does this for me, however when utilizing it inside the options area, as described by the documentation, it has no effect on my chart, regardless of what I write in it. I cannot disable them either, if that's what I wanted to do.
I want the 'options' part below to end up being functional in my chart, as currently it isn't.
The link to the picture showing my issue is below. The values I receive are from a WEB API, so the formatting there is fine. Not sure what's making this issue.
NOTE: adding it with or without quotes makes no difference.
var config = {
"type": "pie",
"data": {
"labels": objLabelsBottom,
"datasets": [{
"label": objLabel1,
"data": objValues1,
"fill": false,
"backgroundColor": [
"rgba(205, 93, 37, 0.2)", "rgba(211, 102, 32, 0.2)", "rgba(181, 111, 35, 0.2)",
"rgba(175, 163, 23, 0.2)", "rgba(195, 172, 124, 0.2)", "rgba(104, 167, 45, 0.2)",
"rgba(185, 218, 82, 0.2)", "rgba(205, 30, 37, 0.2)", "rgba(221, 82, 85, 0.2)",
"rgba(48, 153, 35, 0.2)", "rgba(222, 74, 26, 0.2)", "rgba(195, 181, 107, 0.2)"
],
"borderColor": [
"rgb(205, 93, 37)", "rgb(211, 102, 32)", "rgb(181, 111, 35)", "rgb(175, 163, 23)",
"rgb(195, 172, 124)", "rgb(104, 167, 45)", "rgb(185, 218, 82)", "rgb(205, 30, 37)",
"rgb(221, 82, 85)", "rgb(48, 153, 35)", "rgb(222, 74, 26)", , "rgb(195, 181, 107)"
],
"borderWidth": 1
}
]
},
"options": {
"plugins": {
labels: {
render: 'percentage',
fontColor: function (data) {
var rgb = hexToRgb(data.dataset.backgroundColor[data.index]);
var threshold = 140;
var luminance = 0.299 * rgb.r + 0.587 * rgb.g + 0.114 * rgb.b;
return luminance > threshold ? 'black' : 'white';
},
precision: 2
}
},
"events": ['mousemove', 'mouseout', 'click', 'touchstart', 'touchmove'],
"onClick": (evt, item) => {
handleClick(evt);
}
}
};