JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://code.angularjs.org/1.3.0-rc.4/angular.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.1-beta.2/Chart.min.js"></script>
<div ng-controller="AppController">
<canvas tc-chartjs-line chart-options="options" chart-data="data" auto-legend ng-click="chartClick($event)" chart="chart"></canvas>
</div>
CSS
.tc-chart-js-legend {
list-style-type: none;
padding-left: 0px;
}
.tc-chart-js-legend li {
display: block;
float: left;
clear:both;
padding:10px;
}
.tc-chart-js-legend li span {
width:25px;
height:25px;
display:block;
float:left;
margin-right:10px;
}
JavaScript
var originalLineInitialize = Chart.types.Line.prototype.initialize;
Chart.types.Line.prototype.initialize = function(data) {
// we don't want the labels to separate the x axis from the bottom edge of the graph
var originalLabels = data.labels;
data.labels = data.labels.map(function() { return '' });
originalLineInitialize.apply(this, arguments);
// restore the original labels - because tooltips pick it up from these properties
var xLabels = this.scale.xLabels;
for (var i = 0; i < xLabels.length; i++)
xLabels[i] = originalLabels[i];
this.datasets.forEach(function(dataset) {
dataset.points.forEach(function(point, i) {
point.label = originalLabels[i];
});
});
// override the scale drawing to set the labels to null before drawing
// and back to their original values after the scale is drawn
var originalScaleDraw = this.scale.draw;
this.scale.draw = function() {
// we construct the originalLabels instead of using the previous one
// this allows us to take care of any label updates (eg. in the angular directive)
for (var i = 0; i < this.xLabels.length; i++) {
originalLabels[i] = this.xLabels[i];
this.xLabels[i] = '';
}
originalScaleDraw.apply(this, arguments);
for (var i = 0; i < this.xLabels.length; i++)
this.xLabels[i] = originalLabels[i];
}
}
angular.module( 'app', ['tc.chartjs']);
angular.module( 'app' )
.controller( 'AppController', function( $scope ) {
$scope.chart;
$scope.chartClick = function( event ) {
if ( $scope.chart ) {
// Different methods depending on chart type
console.log( $scope.chart.getPointsAtEvent( event ) ); // for Points
// console.log( $scope.chart.getSegmentsAtEvent( event ) ); // for Segments
}
};
// Chart.js Data
$scope.data = {
labels: ['January', 'February', 'March', 'April', 'May', 'June',...