[Chartjs]-Angular chart how to show the legend data value by default along with legend name

1๐Ÿ‘

Iโ€™m using angular-chart 1.0.2. In my version Iโ€™m using it like this;

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

0๐Ÿ‘

you need to use legendTemplate, make sure you replace the $scope.data in your app ๐Ÿ˜›

var options = {
legendTemplate: "<ul><% for (var i=0; i<data.length; i++){%><li><span style=\"background-color:<%=data[i].color%>\"></span><%=data[i].label%> - <%=data[i].value%></li><%}%></ul>"

}

see this jsfiddle

http://jsfiddle.net/vrwjfg9z/3010/

Leave a comment