Subversion Repositories php-qbpwcf

Rev

Rev 23 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
23 liveuser 1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2
<html>
3
	<head>
4
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
5
		<title>amStock Example</title>
6
		<link rel="stylesheet" href="../amcharts/style.css"
7
		type="text/css">
8
		<script src="../amcharts/amcharts.js" type="text/javascript"></script>
9
		<script src="../amcharts/serial.js" type="text/javascript"></script>
10
		<script src="../amcharts/amstock.js" type="text/javascript"></script>
11
 
12
		<script>
13
			AmCharts.ready(function () {
14
				generateChartData();
15
				createStockChart();
16
			});
17
 
18
			var chart;
19
			var chartData = [];
20
			var newPanel;
21
			var stockPanel;
22
 
23
			function generateChartData() {
24
				var firstDate = new Date();
25
				firstDate.setHours(0, 0, 0, 0);
26
				firstDate.setDate(firstDate.getDate() - 2000);
27
 
28
				for (var i = 0; i < 2000; i++) {
29
					var newDate = new Date(firstDate);
30
 
31
					newDate.setDate(newDate.getDate() + i);
32
 
33
					var open = Math.round(Math.random() * (30) + 100);
34
					var close = open + Math.round(Math.random() * (15) - Math.random() * 10);
35
 
36
					var low;
37
					if (open < close) {
38
						low = open - Math.round(Math.random() * 5);
39
					} else {
40
						low = close - Math.round(Math.random() * 5);
41
					}
42
 
43
					var high;
44
					if (open < close) {
45
						high = close + Math.round(Math.random() * 5);
46
					} else {
47
						high = open + Math.round(Math.random() * 5);
48
					}
49
 
50
					var volume = Math.round(Math.random() * (1000 + i)) + 100 + i;
51
 
52
 
53
					chartData[i] = ({
54
						date: newDate,
55
						open: open,
56
						close: close,
57
						high: high,
58
						low: low,
59
						volume: volume
60
					});
61
				}
62
			}
63
 
64
			function createStockChart() {
65
				chart = new AmCharts.AmStockChart();
66
 
67
				chart.balloon.horizontalPadding = 13;
68
 
69
				// DATASET //////////////////////////////////////////
70
				var dataSet = new AmCharts.DataSet();
71
				dataSet.fieldMappings = [{
72
					fromField: "open",
73
					toField: "open"
74
				}, {
75
					fromField: "close",
76
					toField: "close"
77
				}, {
78
					fromField: "high",
79
					toField: "high"
80
				}, {
81
					fromField: "low",
82
					toField: "low"
83
				}, {
84
					fromField: "volume",
85
					toField: "volume"
86
				}, {
87
					fromField: "value",
88
					toField: "value"
89
				}];
90
				dataSet.color = "#7f8da9";
91
				dataSet.dataProvider = chartData;
92
				dataSet.categoryField = "date";
93
 
94
				chart.dataSets = [dataSet];
95
 
96
				// PANELS ///////////////////////////////////////////
97
				stockPanel = new AmCharts.StockPanel();
98
				stockPanel.title = "Value";
99
 
100
				// graph of first stock panel
101
				var graph = new AmCharts.StockGraph();
102
				graph.type = "candlestick";
103
				graph.openField = "open";
104
				graph.closeField = "close";
105
				graph.highField = "high";
106
				graph.lowField = "low";
107
				graph.valueField = "close";
108
				graph.lineColor = "#7f8da9";
109
				graph.fillColors = "#7f8da9";
110
				graph.negativeLineColor = "#db4c3c";
111
				graph.negativeFillColors = "#db4c3c";
112
				graph.fillAlphas = 1;
113
				graph.balloonText = "open:<b>[[open]]</b><br>close:<b>[[close]]</b><br>low:<b>[[low]]</b><br>high:<b>[[high]]</b>";
114
				graph.useDataSetColors = false;
115
				stockPanel.addStockGraph(graph);
116
 
117
				var stockLegend = new AmCharts.StockLegend();
118
				stockLegend.markerType = "none";
119
				stockLegend.markerSize = 0;
120
				stockLegend.valueTextRegular = undefined;
121
				stockLegend.valueWidth = 250;
122
				stockPanel.stockLegend = stockLegend;
123
 
124
				chart.panels = [stockPanel];
125
 
126
 
127
				// OTHER SETTINGS ////////////////////////////////////
128
				var sbsettings = new AmCharts.ChartScrollbarSettings();
129
				sbsettings.graph = graph;
130
				sbsettings.graphType = "line";
131
				sbsettings.usePeriod = "WW";
132
				chart.chartScrollbarSettings = sbsettings;
133
 
134
				// Enable pan events
135
				var panelsSettings = new AmCharts.PanelsSettings();
136
				panelsSettings.panEventsEnabled = true;
137
				chart.panelsSettings = panelsSettings;
138
 
139
				// CURSOR
140
				var cursorSettings = new AmCharts.ChartCursorSettings();
141
				cursorSettings.valueBalloonsEnabled = true;
142
				cursorSettings.fullWidth = true;
143
				cursorSettings.cursorAlpha = 0.1;
144
				chart.chartCursorSettings = cursorSettings;
145
 
146
				// PERIOD SELECTOR ///////////////////////////////////
147
				var periodSelector = new AmCharts.PeriodSelector();
148
				periodSelector.position = "bottom";
149
				periodSelector.periods = [{
150
					period: "DD",
151
					count: 10,
152
					label: "10 days"
153
				}, {
154
					period: "MM",
155
					selected: true,
156
					count: 1,
157
					label: "1 month"
158
				}, {
159
					period: "YYYY",
160
					count: 1,
161
					label: "1 year"
162
				}, {
163
					period: "YTD",
164
					label: "YTD"
165
				}, {
166
					period: "MAX",
167
					label: "MAX"
168
				}];
169
				chart.periodSelector = periodSelector;
170
 
171
 
172
				chart.write('chartdiv');
173
			}
174
 
175
 
176
 
177
			function addPanel() {
178
				newPanel = new AmCharts.StockPanel();
179
				newPanel.allowTurningOff = true;
180
				newPanel.title = "Volume";
181
				newPanel.showCategoryAxis = false;
182
 
183
				var graph = new AmCharts.StockGraph();
184
				graph.valueField = "volume";
185
				graph.fillAlphas = 0.15;
186
				newPanel.addStockGraph(graph);
187
 
188
				var legend = new AmCharts.StockLegend();
189
				legend.markerType = "none";
190
				legend.markerSize = 0;
191
				newPanel.stockLegend = legend;
192
 
193
				chart.addPanelAt(newPanel, 1);
194
				chart.validateNow();
195
 
196
				document.getElementById("addPanelButton").disabled = true;
197
				document.getElementById("removePanelButton").disabled = false;
198
			}
199
 
200
			function removePanel() {
201
				chart.removePanel(newPanel);
202
				chart.validateNow();
203
 
204
				document.getElementById("addPanelButton").disabled = false;
205
				document.getElementById("removePanelButton").disabled = true;
206
			}
207
 
208
		</script>
209
	</head>
210
	<body style="background-color:#FFFFFF">
211
		<input type="button" id="addPanelButton" onclick="addPanel()" value="add panel">
212
		<input type="button" disabled="true" id="removePanelButton" onclick="removePanel()"
213
		value="remove panel">
214
		<div id="chartdiv" style="width:100%; height:600px;"></div>
215
	</body>
216
 
217
</html>