highcharts再angularJS中生成单例图表非常容易,但是生成多图表比较困难。为此研究了很久。以下为详细说明。
准备工作:1、在directive中封装一个highcharts的指令。
app.directive('highcharts', function () {
return {
require: '?ngModel',
restrict: 'EA',
link: function (scope, element, attrs, ngModel) {
//选项
var opts = angular.extend({
title: {text: '', enabled: false},
chart: {type: 'column'},
credits: {enabled: false},
//显示打印
exporting: {
enabled: false
},
xAxis: {
labels: {
y: -10, //x轴标签位置
enabled: false
}
},
yAxis: {
allowDecimals: true,
title: {
text: ' '
}
},
series: [],
tooltip: {}
}, scope.$eval(attrs.highcharts));
// var chartrsID = "#" + pagerID;
var opt_data = opts.data;
var new_opts = {
title: opts.title,
chart: opts.chart,
credits: opts.credits,
exporting: opts.exporting,
xAxis: opts.xAxis,
yAxis: opts.yAxis,
series: [],
tooltip: opts.tooltip,
};
var initChart = function () {
new_opts.plotOptions = {
column: {
pointPadding: 0.2,
borderWidth: 0
},
series: {
cursor: 'pointer',
point: {
events: {
click: function (opt) {
if (new_opts.series[opt.point.series.index].url != undefined)