jtblin / angular-chart.js

Reactive, responsive, beautiful charts for AngularJS using Chart.js: http://jtblin.github.io/angular-chart.js
Other
2.67k stars 761 forks source link

does angular-chart.js work with ngRoute ?? #600

Closed ckuruvi closed 7 years ago

ckuruvi commented 7 years ago

Overview

Describe the issue. What is the issue and what did you expect? I'm unable to display charts on my home.html page using ngRoute. Attaching code snippets for the five files as well below.

Please make sure to review and check all of these items:

Step to reproduce

Index.html

<!DOCTYPE html>

module.js

var chartApp= angular.module('chartApp', ['chart.js']); var myApp = angular.module('passportApp',['ngRoute','chartApp']);

routerconfig.js myApp.config(function($routeProvider, $locationProvider) { $locationProvider.html5Mode(true); $routeProvider .when("/home", { templateUrl: "views/home.html", controller: "HomeController as home", authRequired: true }) .otherwise({ templateUrl: "views/login.html", controller: "LoginController as login" });

home.html

<canvas id="base" class="chart-bar" chart-data="home.data" chart-labels="home.labels" chart-colors="home.colors" chart-dataset-override="home.datasetOverride" >

home.controller.js

myApp.controller('HomeController', function($http, $location){

ctrl.displayChart=function(){ console.log('inside displayChart function'); ctrl.colors = ['#45b7cd', '#ff6384', '#ff8e72'];

ctrl.labels = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
ctrl.data = [
  [65, -59, 80, 81, -56, 55, -40],
  [28, 48, -40, 19, 86, 27, 90]
];
ctrl.datasetOverride = [
  {
    label: "Line chart",
    borderWidth: 1,
    type: 'line'
  },
  {
    label: "Line chart",
    borderWidth: 3,
    hoverBackgroundColor: "rgba(255,99,132,0.4)",
    hoverBorderColor: "rgba(255,99,132,1)",
    type: 'line'
  }
];

}

});

Ensure you add a link to a plunker, jsbin, or equivalent. Issues without repro steps may be closed immediately.

Here is a jsbin template for 0.x version and one for 1.x for convenience.

jtblin commented 7 years ago

It should work with ng-route.