Blame view

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