| 23 |
liveuser |
1 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
|
|
2 |
<html>
|
|
|
3 |
|
|
|
4 |
<head>
|
|
|
5 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
|
6 |
<title>amCharts examples</title>
|
|
|
7 |
<link rel="stylesheet" href="style.css" type="text/css">
|
|
|
8 |
<script src="../amcharts/amcharts.js" type="text/javascript"></script>
|
|
|
9 |
<script src="../amcharts/serial.js" type="text/javascript"></script>
|
|
|
10 |
|
|
|
11 |
<script>
|
|
|
12 |
// note, we have townName field with a name specified for each datapoint and townName2 with only some of the names specified.
|
|
|
13 |
// we use townName2 to display town names next to the bullet. And as these names would overlap if displayed next to each bullet,
|
|
|
14 |
// we created this townName2 field and set only some of the names for this purpse.
|
|
|
15 |
var chartData = [
|
|
|
16 |
{
|
|
|
17 |
"date": "2012-01-01",
|
|
|
18 |
"distance": 227,
|
|
|
19 |
"townName": "New York",
|
|
|
20 |
"townName2": "New York",
|
|
|
21 |
"townSize": 25,
|
|
|
22 |
"latitude": 40.71,
|
|
|
23 |
"duration": 408
|
|
|
24 |
},
|
|
|
25 |
{
|
|
|
26 |
"date": "2012-01-02",
|
|
|
27 |
"distance": 371,
|
|
|
28 |
"townName": "Washington",
|
|
|
29 |
"townSize": 14,
|
|
|
30 |
"latitude": 38.89,
|
|
|
31 |
"duration": 482
|
|
|
32 |
},
|
|
|
33 |
{
|
|
|
34 |
"date": "2012-01-03",
|
|
|
35 |
"distance": 433,
|
|
|
36 |
"townName": "Wilmington",
|
|
|
37 |
"townSize": 6,
|
|
|
38 |
"latitude": 34.22,
|
|
|
39 |
"duration": 562
|
|
|
40 |
},
|
|
|
41 |
{
|
|
|
42 |
"date": "2012-01-04",
|
|
|
43 |
"distance": 345,
|
|
|
44 |
"townName": "Jacksonville",
|
|
|
45 |
"townSize": 7,
|
|
|
46 |
"latitude": 30.35,
|
|
|
47 |
"duration": 379
|
|
|
48 |
},
|
|
|
49 |
{
|
|
|
50 |
"date": "2012-01-05",
|
|
|
51 |
"distance": 480,
|
|
|
52 |
"townName": "Miami",
|
|
|
53 |
"townName2": "Miami",
|
|
|
54 |
"townSize": 10,
|
|
|
55 |
"latitude": 25.83,
|
|
|
56 |
"duration": 501
|
|
|
57 |
},
|
|
|
58 |
{
|
|
|
59 |
"date": "2012-01-06",
|
|
|
60 |
"distance": 386,
|
|
|
61 |
"townName": "Tallahassee",
|
|
|
62 |
"townSize": 7,
|
|
|
63 |
"latitude": 30.46,
|
|
|
64 |
"duration": 443
|
|
|
65 |
},
|
|
|
66 |
{
|
|
|
67 |
"date": "2012-01-07",
|
|
|
68 |
"distance": 348,
|
|
|
69 |
"townName": "New Orleans",
|
|
|
70 |
"townSize": 10,
|
|
|
71 |
"latitude": 29.94,
|
|
|
72 |
"duration": 405
|
|
|
73 |
},
|
|
|
74 |
{
|
|
|
75 |
"date": "2012-01-08",
|
|
|
76 |
"distance": 238,
|
|
|
77 |
"townName": "Houston",
|
|
|
78 |
"townName2": "Houston",
|
|
|
79 |
"townSize": 16,
|
|
|
80 |
"latitude": 29.76,
|
|
|
81 |
"duration": 309
|
|
|
82 |
},
|
|
|
83 |
{
|
|
|
84 |
"date": "2012-01-09",
|
|
|
85 |
"distance": 218,
|
|
|
86 |
"townName": "Dalas",
|
|
|
87 |
"townSize": 17,
|
|
|
88 |
"latitude": 32.8,
|
|
|
89 |
"duration": 287
|
|
|
90 |
},
|
|
|
91 |
{
|
|
|
92 |
"date": "2012-01-10",
|
|
|
93 |
"distance": 349,
|
|
|
94 |
"townName": "Oklahoma City",
|
|
|
95 |
"townSize": 11,
|
|
|
96 |
"latitude": 35.49,
|
|
|
97 |
"duration": 485
|
|
|
98 |
},
|
|
|
99 |
{
|
|
|
100 |
"date": "2012-01-11",
|
|
|
101 |
"distance": 603,
|
|
|
102 |
"townName": "Kansas City",
|
|
|
103 |
"townSize": 10,
|
|
|
104 |
"latitude": 39.1,
|
|
|
105 |
"duration": 890
|
|
|
106 |
},
|
|
|
107 |
{
|
|
|
108 |
"date": "2012-01-12",
|
|
|
109 |
"distance": 534,
|
|
|
110 |
"townName": "Denver",
|
|
|
111 |
"townName2": "Denver",
|
|
|
112 |
"townSize": 18,
|
|
|
113 |
"latitude": 39.74,
|
|
|
114 |
"duration": 810
|
|
|
115 |
},
|
|
|
116 |
{
|
|
|
117 |
"date": "2012-01-13",
|
|
|
118 |
"townName": "Salt Lake City",
|
|
|
119 |
"townSize": 12,
|
|
|
120 |
"distance": 425,
|
|
|
121 |
"duration": 670,
|
|
|
122 |
"latitude": 40.75,
|
|
|
123 |
"dashLength": 8,
|
|
|
124 |
"alpha":0.4
|
|
|
125 |
},
|
|
|
126 |
{
|
|
|
127 |
"date": "2012-01-14",
|
|
|
128 |
"latitude": 36.1,
|
|
|
129 |
"duration": 470,
|
|
|
130 |
"townName": "Las Vegas",
|
|
|
131 |
"townName2": "Las Vegas"
|
|
|
132 |
},
|
|
|
133 |
{
|
|
|
134 |
"date": "2012-01-15"
|
|
|
135 |
},
|
|
|
136 |
{
|
|
|
137 |
"date": "2012-01-16"
|
|
|
138 |
},
|
|
|
139 |
{
|
|
|
140 |
"date": "2012-01-17"
|
|
|
141 |
},
|
|
|
142 |
{
|
|
|
143 |
"date": "2012-01-18"
|
|
|
144 |
},
|
|
|
145 |
{
|
|
|
146 |
"date": "2012-01-19"
|
|
|
147 |
}
|
|
|
148 |
];
|
|
|
149 |
var chart;
|
|
|
150 |
|
|
|
151 |
AmCharts.ready(function () {
|
|
|
152 |
// SERIAL CHART
|
|
|
153 |
chart = new AmCharts.AmSerialChart();
|
|
|
154 |
chart.dataProvider = chartData;
|
|
|
155 |
chart.categoryField = "date";
|
|
|
156 |
chart.dataDateFormat = "YYYY-MM-DD";
|
|
|
157 |
chart.color = "#FFFFFF";
|
|
|
158 |
chart.marginLeft = 0;
|
|
|
159 |
|
|
|
160 |
// AXES
|
|
|
161 |
// category
|
|
|
162 |
var categoryAxis = chart.categoryAxis;
|
|
|
163 |
categoryAxis.parseDates = true; // as our data is date-based, we set parseDates to true
|
|
|
164 |
categoryAxis.minPeriod = "DD"; // our data is daily, so we set minPeriod to DD
|
|
|
165 |
categoryAxis.autoGridCount = false;
|
|
|
166 |
categoryAxis.gridCount = 50;
|
|
|
167 |
categoryAxis.gridAlpha = 0.1;
|
|
|
168 |
categoryAxis.gridColor = "#FFFFFF";
|
|
|
169 |
categoryAxis.axisColor = "#555555";
|
|
|
170 |
// we want custom date formatting, so we change it in next line
|
|
|
171 |
categoryAxis.dateFormats = [{
|
|
|
172 |
period: 'DD',
|
|
|
173 |
format: 'DD'
|
|
|
174 |
}, {
|
|
|
175 |
period: 'WW',
|
|
|
176 |
format: 'MMM DD'
|
|
|
177 |
}, {
|
|
|
178 |
period: 'MM',
|
|
|
179 |
format: 'MMM'
|
|
|
180 |
}, {
|
|
|
181 |
period: 'YYYY',
|
|
|
182 |
format: 'YYYY'
|
|
|
183 |
}];
|
|
|
184 |
|
|
|
185 |
// as we have data of different units, we create three different value axes
|
|
|
186 |
// Distance value axis
|
|
|
187 |
var distanceAxis = new AmCharts.ValueAxis();
|
|
|
188 |
distanceAxis.title = "distance";
|
|
|
189 |
distanceAxis.gridAlpha = 0;
|
|
|
190 |
distanceAxis.axisAlpha = 0;
|
|
|
191 |
chart.addValueAxis(distanceAxis);
|
|
|
192 |
|
|
|
193 |
// latitude value axis
|
|
|
194 |
var latitudeAxis = new AmCharts.ValueAxis();
|
|
|
195 |
latitudeAxis.gridAlpha = 0;
|
|
|
196 |
latitudeAxis.axisAlpha = 0;
|
|
|
197 |
latitudeAxis.labelsEnabled = false;
|
|
|
198 |
latitudeAxis.position = "right";
|
|
|
199 |
chart.addValueAxis(latitudeAxis);
|
|
|
200 |
|
|
|
201 |
// duration value axis
|
|
|
202 |
var durationAxis = new AmCharts.ValueAxis();
|
|
|
203 |
durationAxis.title = "duration";
|
|
|
204 |
// the following line makes this value axis to convert values to duration
|
|
|
205 |
// it tells the axis what duration unit it should use. mm - minute, hh - hour...
|
|
|
206 |
durationAxis.duration = "mm";
|
|
|
207 |
durationAxis.durationUnits = {
|
|
|
208 |
DD: "d. ",
|
|
|
209 |
hh: "h ",
|
|
|
210 |
mm: "min",
|
|
|
211 |
ss: ""
|
|
|
212 |
};
|
|
|
213 |
durationAxis.gridAlpha = 0;
|
|
|
214 |
durationAxis.axisAlpha = 0;
|
|
|
215 |
durationAxis.inside = true;
|
|
|
216 |
durationAxis.position = "right";
|
|
|
217 |
chart.addValueAxis(durationAxis);
|
|
|
218 |
|
|
|
219 |
// GRAPHS
|
|
|
220 |
// distance graph
|
|
|
221 |
var distanceGraph = new AmCharts.AmGraph();
|
|
|
222 |
distanceGraph.valueField = "distance";
|
|
|
223 |
distanceGraph.title = "distance";
|
|
|
224 |
distanceGraph.type = "column";
|
|
|
225 |
distanceGraph.fillAlphas = 0.9;
|
|
|
226 |
distanceGraph.valueAxis = distanceAxis; // indicate which axis should be used
|
|
|
227 |
distanceGraph.balloonText = "[[value]] miles";
|
|
|
228 |
distanceGraph.legendValueText = "[[value]] mi";
|
|
|
229 |
distanceGraph.legendPeriodValueText = "total: [[value.sum]] mi";
|
|
|
230 |
distanceGraph.lineColor = "#263138";
|
|
|
231 |
distanceGraph.dashLengthField = "dashLength";
|
|
|
232 |
distanceGraph.alphaField = "alpha";
|
|
|
233 |
chart.addGraph(distanceGraph);
|
|
|
234 |
|
|
|
235 |
// latitude graph
|
|
|
236 |
var latitudeGraph = new AmCharts.AmGraph();
|
|
|
237 |
latitudeGraph.valueField = "latitude";
|
|
|
238 |
latitudeGraph.title = "latitude/city";
|
|
|
239 |
latitudeGraph.type = "line";
|
|
|
240 |
latitudeGraph.valueAxis = latitudeAxis; // indicate which axis should be used
|
|
|
241 |
latitudeGraph.lineColor = "#786c56";
|
|
|
242 |
latitudeGraph.lineThickness = 1;
|
|
|
243 |
latitudeGraph.legendValueText = "[[description]]/[[value]]";
|
|
|
244 |
latitudeGraph.descriptionField = "townName";
|
|
|
245 |
latitudeGraph.bullet = "round";
|
|
|
246 |
latitudeGraph.bulletSizeField = "townSize"; // indicate which field should be used for bullet size
|
|
|
247 |
latitudeGraph.bulletBorderColor = "#786c56";
|
|
|
248 |
latitudeGraph.bulletBorderAlpha = 1;
|
|
|
249 |
latitudeGraph.bulletBorderThickness = 2;
|
|
|
250 |
latitudeGraph.bulletColor = "#000000";
|
|
|
251 |
latitudeGraph.labelText = "[[townName2]]"; // not all data points has townName2 specified, that's why labels are displayed only near some of the bullets.
|
|
|
252 |
latitudeGraph.labelPosition = "right";
|
|
|
253 |
latitudeGraph.balloonText = "latitude:[[value]]";
|
|
|
254 |
latitudeGraph.showBalloon = true;
|
|
|
255 |
latitudeGraph.dashLengthField = "dashLength";
|
|
|
256 |
chart.addGraph(latitudeGraph);
|
|
|
257 |
|
|
|
258 |
// duration graph
|
|
|
259 |
var durationGraph = new AmCharts.AmGraph();
|
|
|
260 |
durationGraph.title = "duration";
|
|
|
261 |
durationGraph.valueField = "duration";
|
|
|
262 |
durationGraph.type = "line";
|
|
|
263 |
durationGraph.valueAxis = durationAxis; // indicate which axis should be used
|
|
|
264 |
durationGraph.lineColor = "#ff5755";
|
|
|
265 |
durationGraph.balloonText = "[[value]]";
|
|
|
266 |
durationGraph.lineThickness = 1;
|
|
|
267 |
durationGraph.legendValueText = "[[value]]";
|
|
|
268 |
durationGraph.bullet = "square";
|
|
|
269 |
durationGraph.bulletBorderColor = "#ff5755";
|
|
|
270 |
durationGraph.bulletBorderThickness = 1;
|
|
|
271 |
durationGraph.bulletBorderAlpha = 1;
|
|
|
272 |
durationGraph.dashLengthField = "dashLength";
|
|
|
273 |
chart.addGraph(durationGraph);
|
|
|
274 |
|
|
|
275 |
// CURSOR
|
|
|
276 |
var chartCursor = new AmCharts.ChartCursor();
|
|
|
277 |
chartCursor.zoomable = false;
|
|
|
278 |
chartCursor.categoryBalloonDateFormat = "DD";
|
|
|
279 |
chartCursor.cursorAlpha = 0;
|
|
|
280 |
chartCursor.valueBalloonsEnabled = false;
|
|
|
281 |
chart.addChartCursor(chartCursor);
|
|
|
282 |
|
|
|
283 |
// LEGEND
|
|
|
284 |
var legend = new AmCharts.AmLegend();
|
|
|
285 |
legend.bulletType = "round";
|
|
|
286 |
legend.equalWidths = false;
|
|
|
287 |
legend.valueWidth = 120;
|
|
|
288 |
legend.useGraphSettings = true;
|
|
|
289 |
legend.color = "#FFFFFF";
|
|
|
290 |
chart.addLegend(legend);
|
|
|
291 |
|
|
|
292 |
// WRITE
|
|
|
293 |
chart.write("chartdiv");
|
|
|
294 |
});
|
|
|
295 |
</script>
|
|
|
296 |
</head>
|
|
|
297 |
|
|
|
298 |
<body style="background-color:#161616">
|
|
|
299 |
<div id="chartdiv" style="width:100%; height:400px;"></div>
|
|
|
300 |
</body>
|
|
|
301 |
|
|
|
302 |
</html>
|