-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDirectiveCandlestick.js
99 lines (91 loc) · 2.72 KB
/
DirectiveCandlestick.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
98
99
var weBTrading = angular.module('weBTrading.candlestick', []);
weBTrading.directive('candlestickchart', ['$timeout', function ($timeout)
{
return {
restrict: 'E',
template: "<div><div id='{{candlestickId}}' class='candlestickChart'></div></div>",
replace: true,
scope:
{
accessor: "=",
candlesticksdata: "=",
buyandsellpoints: "=",
candlestickId: "@"
},
link: function (scope, element, attrs)
{
var graph;
$timeout(function ($scope, $element, $attrs)
{
graph = AmCharts.makeChart(scope.candlestickId,
{
"type": "serial",
"theme": "dark",
"dataDateFormat":"YYYY-MM-DDTHH:mm:ss.fffZ",
"valueAxes": [
{
"position": "left"
} ],
"graphs": [ {
"id": "g1",
"proCandlesticks": true,
"balloonText": "Open:<b>[[Open]]</b><br>Low:<b>[[Low]]</b><br>High:<b>[[High]]</b><br>Close:<b>[[Close]]</b><br><br>Date:<b>[[Date]]</b><br>",
"closeField": "Close",
"fillColors": "#7f8da9",
"highField": "High",
"lineColor": "#7f8da9",
"lineAlpha": 1,
"lowField": "Low",
"fillAlphas": 0.9,
"negativeFillColors": "#db4c3c",
"negativeLineColor": "#db4c3c",
"openField": "Open",
"title": "Price:",
"type": "candlestick",
"valueField": "Close"
} ],
"chartScrollbar": {
"graph": "g1",
"backgroundAlpha" : 0.1,
"graphFillAlpha" : 0.5,
"graphType": "candlestick",
"scrollbarHeight": 5
},
"chartCursor": {
"valueLineEnabled": true,
"valueLineBalloonEnabled": true
},
"categoryField": "CandleIndex",
// "categoryAxis": {
// "parseDates": false,
// "autoGridCount" : false,
// "minPeriod" : "fff"
// },
"dataProvider": scope.candlesticksdata,
"trendLines" : scope.buyandsellpoints,
"export": {
"enabled": true,
"position": "bottom-right"
}
});
graph.addListener("rendered", zoomChart);
{
//zoomChart();
}
// this method is called when graph is first inited as we listen for "dataUpdated" event
function zoomChart()
{
// different zoom methods can be used - zoomToIndexes, zoomToDates, zoomToCategoryValues
graph.zoomToIndexes( graph.dataProvider.length - 50, graph.dataProvider.length - 1 );
}
zoomChart();
});
scope.accessor.refreshCandlesticks = function ()
{
graph.dataProvider = scope.candlesticksdata;
graph.trendLines = scope.buyandsellpoints;
graph.validateData();
};
}
};
}]);