3

I am using angularjs chart, Chart.min.js and angular-chart.min.js

It shows the legend only the "labels" i want to see also the "data" by default along with the label, either as part of legend or within the pie chart section itself.

can any one help?

    HTML:
    <div class="col-lg-6 col-sm-12" ng-controller="PieCtrl">
                  <div class="panel panel-default">
                    <div class="panel-heading">Pie Chart</div>
                    <div class="panel-body">
                        <canvas id="pie" class="chart chart-pie" chart-data="data" chart-labels="labels" chart-options="options" chart-hover="chartOver"  chart-click="chartPortionClick"></canvas> 
                     </div>
                  </div>
                </div>

    JS:
      var app = angular.module('demoApp', ['chart.js', 'ui.bootstrap']);
          app.controller('PieCtrl', ['$scope', function ($scope) {
            $scope.labels = ['Download Sales', 'In-Store Sales', 'Mail Sales','test'];
            $scope.data = [300, 500, 100, 10];
            $scope.options = { legend: { display: true } };
      }]);
Krish
  • 489
  • 2
  • 8
  • 28

2 Answers2

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>",
};
Alpan Karaca
  • 968
  • 5
  • 12
  • 30
0

you need to use legendTemplate, make sure you replace the $scope.data in your app :P

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/

Nattu Raju
  • 310
  • 1
  • 2
  • 11