0đź‘Ť
I just had the same problem and played with some time with overriding the “legendTemplate” option. I seems that the default legendTemplate uses the invalid variable “datasets” which should be now “segments”.
So the solution could look like the following:
- copy default value for legendTemplate
- replace all “datasets” with “segments”
- add “<%=segments[i].value%>” to the end
Example:
myNewChart = new Chart(chartContext).Pie(data, {
legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<segments.length; i++){%><li><span style=\"background-color:<%=segments[i].strokeColor%>\"></span><%if(segments[i].label){%><%=segments[i].label%> <%=segments[i].value%><%}%></li><%}%></ul>"
});
Sadly, I couldn’t fix the css for the legend so the color coding etc. won’t display.
- Chartjs-DevTools failed to load source map, chart.js behaving abnormally
- Chartjs-How to update a chart on prop change in vue-chartjs
Source:stackexchange.com