javascript - chart js legend template -
i'm trying make custom templates legends in chart js. after looking @ examples familiar syntax 1 thing need know how values data passed in when making chart. have template currently,
"<% var segment_sum = 0;%>" + "<% (var = 0; < data.length; i++) { segment_sum += data[i].value; }%>" + "<ul><% (var i=0; i<segments.length; i++){%>" + "<li>" + "<span style=\"color:<%=segments[i].fillcolor%>\" class=\"legend-num\">" + "<%= math.round(data[i].value / segment_sum * 100) %>" + "</span>" + "<span class=\"legend-percent\">" + "%" + "</span>" + "<span class=\"legend-divider\">" + "|" + "</span>" + "<span class=\"legend-label\">" + "<img src=\"/content/img/star.png\" />" + "</span>" + "</li>" + "<% } %>" + "</ul>";
i found out can use variable "data" had declared locally makes template less reusable because have name dataset "data" specifically. segments have field getting data values?
you can access data chart elements collection. example, pie chart
mypiechart.segments.foreach(function (segment) { console.log(segment.value) })
likewise each chart type has collection. update()
method under prototype methods section chart type in http://www.chartjs.org/docs
Comments
Post a Comment