forked from bitliner/AngularChart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
angular-chart.js
97 lines (90 loc) · 2.98 KB
/
angular-chart.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
angular.module('AngularChart', []).directive('chart', function () {
return {
restrict:'E',
template:'<div></div>',
transclude:true,
replace:true,
scope: '=',
link:function (scope, element, attrs) {
console.log('oo',attrs,scope[attrs.formatter])
var opt = {
chart:{
renderTo:element[0],
type:'line',
marginRight:130,
marginBottom:40
},
title:{
text:attrs.title,
x:-20 //center
},
subtitle:{
text:attrs.subtitle,
x:-20
},
xAxis:{
//categories:['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun','Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
tickInterval:1,
title:{
text:attrs.xname
}
},
plotOptions:{
lineWidth:0.5
},
yAxis:{
title:{
text:attrs.yname
},
tickInterval:(attrs.yinterval)?new Number(attrs.yinterval):null,
max:attrs.ymax,
min: attrs.ymin
// ,
// plotLines:[
// {
// value:0,
// width:1,
// color:'#808080'
// }
// ]
},
tooltip:{
formatter:scope[attrs.formatter]||function () {
return '<b>' + this.y + '</b>'
}
},
legend:{
layout:'vertical',
align:'right',
verticalAlign:'top',
x:-10,
y:100,
borderWidth:0
},
series:[
{
name:'Tokyo',
data:[7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]
}
]
}
//Update when charts data changes
scope.$watch(function (scope) {
return JSON.stringify({
xAxis:{
categories:scope[attrs.xdata]
},
series:scope[attrs.ydata]
});
}, function (news) {
console.log('ola')
// if (!attrs) return;
news = JSON.parse(news)
if (!news.series)return;
angular.extend(opt,news)
console.log('opt.xAxis.title.text',opt)
var chart = new Highcharts.Chart(opt);
});
}
}
})