Skip to content

Commit a581600

Browse files
committed
first commit, version stable
0 parents  commit a581600

File tree

6 files changed

+147
-0
lines changed

6 files changed

+147
-0
lines changed

angular-chart.js

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

examples/data/line-chart.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{"xData": ["Jan", "Feb", "Mar", "Apr", "May", "Jun","Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],"yData":[{
2+
"name": "Tokyo",
3+
"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]
4+
}, {
5+
"name": "New York",
6+
"data": [-0.2, 0.8, 5.7, 11.3, 17.0, 22.0, 24.8, 24.1, 20.1, 14.1, 8.6, 2.5]
7+
}, {
8+
"name": "Berlin",
9+
"data": [-0.9, 0.6, 3.5, 8.4, 13.5, 17.0, 18.6, 17.9, 14.3, 9.0, 3.9, 1.0]
10+
}, {
11+
"name": "London",
12+
"data": [3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8]
13+
}]}

examples/index.html

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<html ng-app="AngularChartExample">
2+
<head>
3+
<title>Charts Directives - AngularJs</title>
4+
5+
6+
</head>
7+
<body>
8+
9+
<div ng-view></div>
10+
11+
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.3/angular.js"></script>
12+
13+
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
14+
<script type="text/javascript" src="http://code.highcharts.com/highcharts.src.js"></script>
15+
16+
<script type="text/javascript" src="../angular-chart.js"></script>
17+
<script type="text/javascript" src="js/controller.js"></script>
18+
<script type="text/javascript" src="js/app.js"></script>
19+
20+
</body>
21+
</html>

examples/js/app.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
angular.module('AngularChartExample',['AngularChart'], function( $routeProvider, $locationProvider ){
2+
$routeProvider.when('/',{
3+
templateUrl: './views/charts.html',
4+
controller: MainCtrl
5+
})
6+
})

examples/js/controller.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
function MainCtrl($scope, $http){
2+
console.log('ciao')
3+
$http.get('data/line-chart.json').success(function(result){
4+
$scope.lineChartYData=result.yData
5+
$scope.lineChartXData=result.xData
6+
})
7+
}

examples/views/charts.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<h1>Line chart</h1>
2+
<chart title="Line chart example" xData="lineChartXData" yData="lineChartYData" xName="Month" yName="Hit"></chart>
3+
<!-- yInterval, yMin, yMax, subtitle -->

0 commit comments

Comments
 (0)