I am trying to create a chart that has a different inner label compared to its 'legend'. Chart.js shrinks when the legend is too long which pushes my chart to a very tiny size. I took the labels and chopped them off after a certain length and that is the new label. However I dont know how to have two separate labels, one so the Legend is the shortened version and one being the normal length. Here is my code:
function truncLabel(str, maxwidth){
if(str.length > maxwidth) {
str = str.substring(0,24)+"...";
}
return str;
}
for (var i = 0 ; i < labels2Length; i++){
trunc_labels2[i] = formatLabel(labels2[i],20);
}
new Chart(document.getElementById("xxx"), {
type: 'doughnut',
data: {
labels: trunc_labels2,
datasets: [
{
label: labels2,
backgroundColor: ["#3e95cd", "#8e5ea2","#3cba9f","#e8c3b9","#c45850","#5e5ba3","#9fe7aa","#1a5ba3","#6cba1f","#cacf4f"],
data:data2
}
]} //More code follows but isnt needed here
Labels2 correctly returns the full string, while trunc_labels2 correctly returns the truncated string. Other types of charts have this feature (ie bar, line etc) but it seems doughnut doesnt? Thank you