3
votes

I have created a pie chart using angular-chart.js and it works perfectly fine. Now I need to display the data value on each section of the pie which does not work.

I tried using Chart.PieceLabel.js and added the following piece of code in the option section. It didn't work. I am not sure how to use it with angular-chart.js because it was originally written for chart.js

pieceLabel: {
            render: 'label'
        }

I have used the onAnimationComplete but it doesn't seem to work. I do not get any error message. Here's my code. Where am I going wrong? Thanks for your help in advance! :)

html

 <canvas id="pie" class="chart chart-pie"
                    chart-data="data" chart-labels="labels" chart-options="options" width="500" height="300" chart-colors="colors"></canvas>

JS code

$scope.options = {
    legend: {
        display: true,
        position: "bottom"
    },
    tooltipEvents: [],
    showTooltips: true,
    tooltipCaretSize: 0,
    onAnimationComplete: function () {
        this.showTooltip(this.segments, true);
    }
};
$scope.data = tempData;
$scope.labels = tempLabels;

Plunker link: https://embed.plnkr.co/zlBWzJ/

1
Please provide plunker. - KiranPurbey
what you meant by data value?any screenshot - zabusa
@zabusa i meant the data the section of the pie represents. For example, if a section data is 75, I need 75 to be displayed on that particular section of the chart. - Linda
@Linda its showing when you hover on it? - zabusa
go through this link jsfiddle.net/6p545k3z . And let me know if it is useful - KiranPurbey

1 Answers

0
votes

In your plunker, I replaced

<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.3.0/Chart.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-chart.js/1.0.3/angular-chart.min.js"></script> 

With

</script>
<script src="https://rawgit.com/nnnick/Chart.js/v1.0.2/Chart.min.js"></script>
<script src="https://rawgit.com/jtblin/angular-chart.js/0.8.0/dist/angular-chart.min.js"></script>

(function(angular) {
  'use strict';
  angular.module('myApp', ['chart.js'])

    .controller('myController', [function() {
      var ctrl = this;


      ctrl.labels = ["Download Sales", "In-Store Sales", "Mail-Order Sales"];
      ctrl.data = [300, 500, 100];
      ctrl.data.label = [300, 500, 100];

      ctrl.options = {
        legend: {
          display: true,
          position: "bottom"
        },
        tooltipEvents: [],
        showTooltips: true,
        tooltipCaretSize: 0,
        onAnimationComplete: function() {
          this.showTooltip(this.segments, true);
        },
      };


    }]);


})(window.angular);
<link rel="stylesheet" type="text/css" href="https://cdn.rawgit.com/jtblin/angular-chart.js/0.8.0/dist/angular-chart.css">
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.0-rc.0/angular.min.js"></script>
<script src="https://rawgit.com/nnnick/Chart.js/v1.0.2/Chart.min.js"></script>
<script src="https://rawgit.com/jtblin/angular-chart.js/0.8.0/dist/angular-chart.min.js"></script>

<!--
    <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.3.0/Chart.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-chart.js/1.0.3/angular-chart.min.js"></script> 
    -->


<body ng-app="myApp" ng-controller="myController as ctrl">
  <canvas id="pie" class="chart chart-pie" chart-data="ctrl.data" chart-labels="ctrl.labels" chart-options="ctrl.options">
    </canvas>

</body>