line chart with ChartJS
HTML
<link rel="stylesheet" href="https://rawgit.com/jtblin/angular-chart.js/master/dist/angular-chart.css">
<script src="https://rawgit.com/nnnick/Chart.js/v1.0.2/Chart.min.js"></script>
<script src="https://rawgit.com/jtblin/angular-chart.js/master/dist/angular-chart.min.js"></script>
<div ng-app="MyApp">
<ion-content ng-controller="AgeController">
<canvas id="line" class="chart chart-line-alt" data="data" labels="labels" legend="true" series="series" options="options" click="onClick" colours="['Red','Yellow']" width="402" height="201" style="width: 402px; height: 201px"></canvas>
</ion-content>
</div>
JavaScript
Chart.types.Line.extend({
name: "LineAlt",
initialize: function (data) {
if (this.options.yAxisLabel) this.options.scaleLabel = ' ' + this.options.scaleLabel;
Chart.types.Line.prototype.initialize.apply(this, arguments);
if (this.options.yAxisLabel) this.scale.yAxisLabel = this.options.yAxisLabel;
},
draw: function () {
Chart.types.Line.prototype.draw.apply(this, arguments);
if (this.scale.yAxisLabel) {
var ctx = this.chart.ctx;
ctx.save();
// text alignment and color
ctx.textAlign = "center";
ctx.textBaseline = "bottom";
ctx.fillStyle = this.options.scaleFontColor;
// position
var x = this.scale.xScalePaddingLeft * 0.2;
var y = this.chart.height / 2;
// change origin
ctx.translate(x, y)
// rotate text
ctx.rotate(-90 * Math.PI / 180);
ctx.fillText(this.scale.yAxisLabel, 0, 0);
ctx.restore();
}
}
});
angular.module('chart.js')
.directive('chartLineAlt', ['ChartJsFactory', function (ChartJsFactory) {
return new ChartJsFactory('LineAlt');
}]);
app = angular.module("MyApp", ['chart.js'])
app.controller('AgeController', ['$scope', '$http', function ($scope, $http) {
$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.options = {
yAxisLabel: "My Y Axis Label",
}
}]);