Skip to content

Instantly share code, notes, and snippets.

@lxfontes
Created August 17, 2014 02:50
Show Gist options
  • Select an option

  • Save lxfontes/5595717bc10ef843fef5 to your computer and use it in GitHub Desktop.

Select an option

Save lxfontes/5595717bc10ef843fef5 to your computer and use it in GitHub Desktop.
SimpleMorris
'use strict';
angular.module('simpleMorris', []);
var morrisTypes = {
lineChart: Morris.Line,
areaChart: Morris.Area,
barChart: Morris.Bar,
donutChart: Morris.Donut
};
angular.forEach(morrisTypes, function(mType, dirName) {
angular.module('simpleMorris')
.directive(dirName, function(){
return {
restrict: 'A',
scope: {
chartData: '=',
chartOptions: '='
},
link: function (scope, elem, attrs){
scope.$watch('chartData', function(){
if(scope.chartData){
if (scope.chart) {
scope.chart.setData(scope.chartData);
} else {
var options = scope.chartOptions;
options.element = elem;
options.data = scope.chartData;
scope.chart = new mType(options);
}
}
});
}
}
});
});
<div area-chart
chart-data='series'
chart-options='chart_options'></div>
$scope.chart_options = {
xkey: 'time',
ykeys: ['value'],
labels: ['Value'],
hideHover: true
};
$scope.series = [
{time: 11111111, value: 123},
{time: 11111112, value: 125},
{time: 11111113, value: 126},
{time: 11111114, value: 133},
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment