| 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" type="text/css">
|
|
|
7 |
|
|
|
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 chartData = [];
|
|
|
19 |
|
|
|
20 |
function generateChartData() {
|
|
|
21 |
var firstDate = new Date(2012, 0, 1);
|
|
|
22 |
firstDate.setDate(firstDate.getDate() - 500);
|
|
|
23 |
firstDate.setHours(0, 0, 0, 0);
|
|
|
24 |
|
|
|
25 |
for (var i = 0; i < 500; i++) {
|
|
|
26 |
var newDate = new Date(firstDate);
|
|
|
27 |
newDate.setDate(newDate.getDate() + i);
|
|
|
28 |
|
|
|
29 |
var a = Math.round(Math.random() * (40 + i)) + 100 + i;
|
|
|
30 |
var b = Math.round(Math.random() * 100000000);
|
|
|
31 |
|
|
|
32 |
chartData.push({
|
|
|
33 |
date: newDate,
|
|
|
34 |
value: a,
|
|
|
35 |
volume: b
|
|
|
36 |
});
|
|
|
37 |
}
|
|
|
38 |
}
|
|
|
39 |
|
|
|
40 |
var chart;
|
|
|
41 |
|
|
|
42 |
function createStockChart() {
|
|
|
43 |
chart = new AmCharts.AmStockChart();
|
|
|
44 |
|
|
|
45 |
|
|
|
46 |
// DATASETS //////////////////////////////////////////
|
|
|
47 |
var dataSet = new AmCharts.DataSet();
|
|
|
48 |
dataSet.color = "#b0de09";
|
|
|
49 |
dataSet.fieldMappings = [{
|
|
|
50 |
fromField: "value",
|
|
|
51 |
toField: "value"
|
|
|
52 |
}, {
|
|
|
53 |
fromField: "volume",
|
|
|
54 |
toField: "volume"
|
|
|
55 |
}];
|
|
|
56 |
dataSet.dataProvider = chartData;
|
|
|
57 |
dataSet.categoryField = "date";
|
|
|
58 |
|
|
|
59 |
// set data sets to the chart
|
|
|
60 |
chart.dataSets = [dataSet];
|
|
|
61 |
|
|
|
62 |
// PANELS ///////////////////////////////////////////
|
|
|
63 |
// first stock panel
|
|
|
64 |
var stockPanel1 = new AmCharts.StockPanel();
|
|
|
65 |
stockPanel1.showCategoryAxis = false;
|
|
|
66 |
stockPanel1.title = "Value";
|
|
|
67 |
stockPanel1.percentHeight = 70;
|
|
|
68 |
|
|
|
69 |
// graph of first stock panel
|
|
|
70 |
var graph1 = new AmCharts.StockGraph();
|
|
|
71 |
graph1.valueField = "value";
|
|
|
72 |
stockPanel1.addStockGraph(graph1);
|
|
|
73 |
|
|
|
74 |
// create stock legend
|
|
|
75 |
var stockLegend1 = new AmCharts.StockLegend();
|
|
|
76 |
stockLegend1.valueTextRegular = " ";
|
|
|
77 |
stockLegend1.markerType = "none";
|
|
|
78 |
stockPanel1.stockLegend = stockLegend1;
|
|
|
79 |
|
|
|
80 |
|
|
|
81 |
// second stock panel
|
|
|
82 |
var stockPanel2 = new AmCharts.StockPanel();
|
|
|
83 |
stockPanel2.title = "Volume";
|
|
|
84 |
stockPanel2.percentHeight = 30;
|
|
|
85 |
var graph2 = new AmCharts.StockGraph();
|
|
|
86 |
graph2.valueField = "volume";
|
|
|
87 |
graph2.type = "column";
|
|
|
88 |
graph2.fillAlphas = 1;
|
|
|
89 |
stockPanel2.addStockGraph(graph2);
|
|
|
90 |
|
|
|
91 |
// create stock legend
|
|
|
92 |
var stockLegend2 = new AmCharts.StockLegend();
|
|
|
93 |
stockLegend2.valueTextRegular = " ";
|
|
|
94 |
stockLegend2.markerType = "none";
|
|
|
95 |
stockPanel2.stockLegend = stockLegend2;
|
|
|
96 |
|
|
|
97 |
// set panels to the chart
|
|
|
98 |
chart.panels = [stockPanel1, stockPanel2];
|
|
|
99 |
|
|
|
100 |
|
|
|
101 |
// OTHER SETTINGS ////////////////////////////////////
|
|
|
102 |
var scrollbarSettings = new AmCharts.ChartScrollbarSettings();
|
|
|
103 |
scrollbarSettings.graph = graph1;
|
|
|
104 |
scrollbarSettings.updateOnReleaseOnly = false;
|
|
|
105 |
chart.chartScrollbarSettings = scrollbarSettings;
|
|
|
106 |
|
|
|
107 |
var cursorSettings = new AmCharts.ChartCursorSettings();
|
|
|
108 |
cursorSettings.valueBalloonsEnabled = true;
|
|
|
109 |
cursorSettings.graphBulletSize = 1;
|
|
|
110 |
chart.chartCursorSettings = cursorSettings;
|
|
|
111 |
|
|
|
112 |
|
|
|
113 |
// PERIOD SELECTOR ///////////////////////////////////
|
|
|
114 |
var periodSelector = new AmCharts.PeriodSelector();
|
|
|
115 |
periodSelector.periods = [{
|
|
|
116 |
period: "DD",
|
|
|
117 |
count: 10,
|
|
|
118 |
label: "10 days"
|
|
|
119 |
}, {
|
|
|
120 |
period: "MM",
|
|
|
121 |
count: 1,
|
|
|
122 |
label: "1 month"
|
|
|
123 |
}, {
|
|
|
124 |
period: "YYYY",
|
|
|
125 |
count: 1,
|
|
|
126 |
selected:true,
|
|
|
127 |
label: "1 year"
|
|
|
128 |
}, {
|
|
|
129 |
period: "YTD",
|
|
|
130 |
label: "YTD"
|
|
|
131 |
}, {
|
|
|
132 |
period: "MAX",
|
|
|
133 |
label: "MAX"
|
|
|
134 |
}];
|
|
|
135 |
chart.periodSelector = periodSelector;
|
|
|
136 |
|
|
|
137 |
|
|
|
138 |
var panelsSettings = new AmCharts.PanelsSettings();
|
|
|
139 |
panelsSettings.marginRight = 16;
|
|
|
140 |
panelsSettings.marginLeft = 16;
|
|
|
141 |
panelsSettings.usePrefixes = true;
|
|
|
142 |
chart.panelsSettings = panelsSettings;
|
|
|
143 |
|
|
|
144 |
|
|
|
145 |
// EVENTS
|
|
|
146 |
var e0 = {
|
|
|
147 |
date: new Date(2010, 8, 19),
|
|
|
148 |
type: "sign",
|
|
|
149 |
backgroundColor: "#85CDE6",
|
|
|
150 |
graph: graph1,
|
|
|
151 |
text: "S",
|
|
|
152 |
description: "This is description of an event"
|
|
|
153 |
};
|
|
|
154 |
var e1 = {
|
|
|
155 |
date: new Date(2010, 10, 19),
|
|
|
156 |
type: "flag",
|
|
|
157 |
backgroundColor: "#FFFFFF",
|
|
|
158 |
backgroundAlpha: 0.5,
|
|
|
159 |
graph: graph1,
|
|
|
160 |
text: "F",
|
|
|
161 |
description: "Some longer\ntext can also\n be added"
|
|
|
162 |
};
|
|
|
163 |
var e2 = {
|
|
|
164 |
date: new Date(2010, 11, 10),
|
|
|
165 |
showOnAxis: true,
|
|
|
166 |
backgroundColor: "#85CDE6",
|
|
|
167 |
type: "pin",
|
|
|
168 |
text: "X",
|
|
|
169 |
graph: graph1,
|
|
|
170 |
description: "This is description of an event"
|
|
|
171 |
};
|
|
|
172 |
var e3 = {
|
|
|
173 |
date: new Date(2010, 11, 26),
|
|
|
174 |
showOnAxis: true,
|
|
|
175 |
backgroundColor: "#85CDE6",
|
|
|
176 |
type: "pin",
|
|
|
177 |
text: "Z",
|
|
|
178 |
graph: graph1,
|
|
|
179 |
description: "This is description of an event"
|
|
|
180 |
};
|
|
|
181 |
var e4 = {
|
|
|
182 |
date: new Date(2011, 0, 3),
|
|
|
183 |
type: "sign",
|
|
|
184 |
backgroundColor: "#85CDE6",
|
|
|
185 |
graph: graph1,
|
|
|
186 |
text: "U",
|
|
|
187 |
description: "This is description of an event"
|
|
|
188 |
};
|
|
|
189 |
var e5 = {
|
|
|
190 |
date: new Date(2011, 1, 6),
|
|
|
191 |
type: "sign",
|
|
|
192 |
graph: graph1,
|
|
|
193 |
text: "D",
|
|
|
194 |
description: "This is description of an event"
|
|
|
195 |
};
|
|
|
196 |
var e6 = {
|
|
|
197 |
date: new Date(2011, 3, 5),
|
|
|
198 |
type: "sign",
|
|
|
199 |
graph: graph1,
|
|
|
200 |
text: "L",
|
|
|
201 |
description: "This is description of an event"
|
|
|
202 |
};
|
|
|
203 |
var e7 = {
|
|
|
204 |
date: new Date(2011, 3, 5),
|
|
|
205 |
type: "sign",
|
|
|
206 |
graph: graph1,
|
|
|
207 |
text: "R",
|
|
|
208 |
description: "This is description of an event"
|
|
|
209 |
};
|
|
|
210 |
var e8 = {
|
|
|
211 |
date: new Date(2011, 5, 15),
|
|
|
212 |
type: "arrowUp",
|
|
|
213 |
backgroundColor: "#00CC00",
|
|
|
214 |
graph: graph1,
|
|
|
215 |
description: "This is description of an event"
|
|
|
216 |
};
|
|
|
217 |
var e9 = {
|
|
|
218 |
date: new Date(2011, 6, 25),
|
|
|
219 |
type: "arrowDown",
|
|
|
220 |
backgroundColor: "#CC0000",
|
|
|
221 |
graph: graph1,
|
|
|
222 |
description: "This is description of an event"
|
|
|
223 |
};
|
|
|
224 |
var e10 = {
|
|
|
225 |
date: new Date(2011, 8, 1),
|
|
|
226 |
type: "text",
|
|
|
227 |
graph: graph1,
|
|
|
228 |
text: "Longer text can\nalso be displayed",
|
|
|
229 |
description: "This is description of an event"
|
|
|
230 |
};
|
|
|
231 |
|
|
|
232 |
dataSet.stockEvents = [e0, e1, e2, e3, e4, e5, e6, e7, e8, e9, e10];
|
|
|
233 |
|
|
|
234 |
chart.write('chartdiv');
|
|
|
235 |
}
|
|
|
236 |
|
|
|
237 |
</script>
|
|
|
238 |
</head>
|
|
|
239 |
<body style="background-color:#FFFFFF">
|
|
|
240 |
<div id="chartdiv" style="width:100%; height:600px;"></div>
|
|
|
241 |
</body>
|
|
|
242 |
|
|
|
243 |
</html>
|