JavaScript return percentage in chart.js (v2+) legend

Chart.js 2+ does not return percentages for legend items in pie charts anymore.

I am storing the legend in the separate item in my html named #legend. Then I set it's innerHTML to myPieChart.generateLegend(). It returns both the color and name but I'd like to be able to override this HTML template to also return percentages, so the output goes from looking like:

  • A
  • B
  • C

to:

  • A (13%)
  • B (50%)
  • C (37%)

I used to do it with the legendTemplate argument but it does not seem to work anymore:

legendTemplate: "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<segments.length; i++){%><li><span style=\"background-color:<%=segments[i].fillColor%>\"></span><%if(segments[i].label){%><%=segments[i].label%> (<%=segments[i].value%>%)<%}%></li><%}%></ul>"
Answer:1

I want to save and an image that is user generated, and I can't use anything other than HTML an JavaScript. Is there a way to do it? Any help is appreciated.

I want to save and an image that is user generated, and I can't use anything other than HTML an JavaScript. Is there a way to do it? Any help is appreciated.

Listening to scroll events in Safari iOS browser triggers the console message every time, even on the momentum, but in the cordova built app that triggers only when the scroll has stopped. el-with-...

Listening to scroll events in Safari iOS browser triggers the console message every time, even on the momentum, but in the cordova built app that triggers only when the scroll has stopped. el-with-...

  1. cordova momentum scrolling

why is it that codeigniter session doesn't update values when an ajax request is done? controller index: public function index() { $this->session->set_userdata( 'greetings', 'hello!' ); } ...

why is it that codeigniter session doesn't update values when an ajax request is done? controller index: public function index() { $this->session->set_userdata( 'greetings', 'hello!' ); } ...

  1. codeigniter session doesn't work

I want to update a variable called hideProgressBar the Directive "ng-hide" in this view through the $ scope in my control. But it does not work. The line below works: $ Scope.hideProgessBar = true; ...

I want to update a variable called hideProgressBar the Directive "ng-hide" in this view through the $ scope in my control. But it does not work. The line below works: $ Scope.hideProgessBar = true; ...