angularjs - How to display multiple charts in the same controller using Chart.js in angular js -


i want display 2 different charts different values of chart.js in same controller, unable do. because unaware of how do. can please me how do, thankyou in advance.

html

<div id="chart_block">     <div class="row">         <div class="col-md-6">             <div class="panel panel-default">                 <div class="panel-heading">                     <h4 class="panel-title">bar chart</h4>                 </div>                 <div class="panel-body">                     <canvas id="bar" class="chart chart-bar"chart-data="data" chart-labels="labels"                             chart-series="series" barchart></canvas>                 </div>             </div>         </div>          <div class="col-md-6">             <div class="panel panel-default">                 <div class="panel-heading">                     <h4 class="panel-title">line chart</h4>                 </div>                 <div class="panel-body">                     <canvas id="line" class="chart chart-line" chart-data="data"                             chart-labels="labels" chart-series="series" chart-options="options"                             chart-dataset-override="datasetoverride" chart-click="onclick"></canvas>                 </div>             </div>         </div>      </div> </div> 

controller

(function () { "use:strict"; angular.module("myapp").controller("chartsctrl", ["$scope", chartsctrl]);  function chartsctrl($scope) { //for first chart     $scope.labels = ['2006', '2007', '2008', '2009', '2010', '2011', '2012'];     $scope.series = ['series a', 'series b'];     $scope.data = [       [65, 59, 80, 81, 56, 55, 40],       [28, 48, 40, 19, 86, 27, 90]     ]; }  //for second chart  $scope.labels = ["january", "february", "march", "april", "may", "june", "july"];   $scope.series = ['series a', 'series b'];   $scope.data = [     [65, 59, 80, 81, 56, 55, 40],     [28, 48, 40, 19, 86, 27, 90]   ];   $scope.onclick = function (points, evt) {     console.log(points, evt);   };   $scope.datasetoverride = [{ yaxisid: 'y-axis-1' }, { yaxisid: 'y-axis-2' }];   $scope.options = {     scales: {       yaxes: [         {           id: 'y-axis-1',           type: 'linear',           display: true,           position: 'left'         },         {           id: 'y-axis-2',           type: 'linear',           display: true,           position: 'right'         }       ]     }   }; 

})();

use different variables.

html code:

<canvas id="bar" class="chart chart-bar" chart-data="data1" chart-labels="labels1" chart-series="series1" barchart></canvas>  <canvas id="line" class="chart chart-line" chart-data="data2" chart-labels="labels2" chart-series="series2" chart-options="options" chart-dataset-override="datasetoverride" chart-click="onclick"></canvas> 

controller code:

$scope.labels1 = ['2006', '2007', '2008', '2009', '2010', '2011', '2012']; $scope.series1 = ['series a', 'series b']; $scope.data1 = [ [65, 59, 80, 81, 56, 55, 40], [28, 48, 40, 19, 86, 27, 90]];   $scope.labels2 = ["january", "february", "march", "april", "may", "june", "july"]; $scope.series2 = ['series a', 'series b']; $scope.data2 = [ [65, 59, 80, 81, 56, 55, 40], [28, 48, 40, 19, 86, 27, 90]]; 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -