Subversion-Projekte lars-tiefland.cienc

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
5 lars 1
# amCharts Data Loader
2
 
3
Version: 1.0.8
4
 
5
 
6
## Description
7
 
8
By default all amCharts libraries accept data in JSON format. It needs to be
9
there when the web page loads, defined in-line or loaded via custom code.
10
 
11
This plugin introduces are native wrapper that enables automatic loading of data
12
from external data data sources in CSV and JSON formats.
13
 
14
Most of the times you will just need to provide a URL of the external data
15
source - static file or dynamically generated - and it will do the rest.
16
 
17
 
18
## Important notice
19
 
20
Due to security measures implemented in most of the browsers, the external data
21
loader will work only when the page with the chart or map is loaded via web
22
server.
23
 
24
So, any of the examples loaded locally (file:///) will not work.
25
 
26
The page needs to be loaded via web server (http://) in order to work properly.
27
 
28
Loading data from another domain than the web page is loaded is possible but is
29
a subject for `Access-Control-Allow-Origin` policies defined by the web server
30
you are loading data from.
31
 
32
For more about loading data across domains use the following thread:
33
http://stackoverflow.com/questions/1653308/access-control-allow-origin-multiple-origin-domains
34
 
35
 
36
## Usage
37
 
38
### 1) Include the minified version of file of this plugin. I.e.:
39
 
40
```
41
<script src="amcharts/plugins/dataloader/dataloader.min.js" type="text/javascript"></script>
42
```
43
 
44
(this needs to go after all the other amCharts includes)
45
 
46
### 2) Add data source properties to your chart configuration.
47
 
48
Regular (Serial, Pie, etc.) charts:
49
 
50
```
51
AmCharts.makeChart( "chartdiv", {
52
  ...,
53
  "dataLoader": {
54
    "url": "data.json",
55
    "format": "json"
56
  }
57
} );
58
```
59
 
60
Stock chart:
61
 
62
```
63
AmCharts.makeChart( "chartdiv", {
64
  ...,
65
  "dataSets": [{
66
    ...,
67
    "dataLoader": {
68
      "url": "data.csv",
69
      "format": "csv",
70
      "delimiter": ",",       // column separator
71
      "useColumnNames": true, // use first row for column names
72
      "skip": 1               // skip header row
73
    }
74
  }]
75
} );
76
```
77
 
78
That's it. The plugin will make sure the files are loaded and dataProvider is
79
populated with their content *before* the chart is built.
80
 
81
Some formats, like CSV, will require additional parameters needed to parse the
82
data, such as "separator".
83
 
84
If the "format" is omitted, the plugin will assume JSON.
85
 
86
 
87
## Complete list of available dataLoader settings
88
 
89
Property | Default | Description
90
-------- | ------- | -----------
91
async | true | If set to false (not recommended) everything will wait until data is fully loaded
92
complete | | Callback function to execute when loader is done
93
delimiter | , | [CSV only] a delimiter for columns (use \t for tab delimiters)
94
error | | Callback function to execute if file load fails
95
format | json | Type of data: json, csv
96
headers | | An array of objects with two properties (key and value) to attach to HTTP request
97
load | | Callback function to execute when file is successfully loaded (might be invoked multiple times)
98
noStyles | false | If set to true no styles will be applied to "Data loading" curtain
99
postProcess | | If set to function reference, that function will be called to "post-process" loaded data before passing it on to chart. The handler function will receive two parameters: loaded data, Data Loader options
100
showErrors | true | Show loading errors in a chart curtain
101
showCurtain | true| Show curtain over the chart area when loading data
102
reload | 0 | Reload data every X seconds
103
reverse | false | [CSV only] add data points in revers order
104
skip | 0 | [CSV only] skip X first rows in data (includes first row if useColumnNames is used)
105
timestamp | false | Add current timestamp to data URLs (to avoid caching)
106
useColumnNames | false | [CSV only] Use first row in data as column names when parsing
107
 
108
 
109
## Using in JavaScript Stock Chart
110
 
111
In JavaScript Stock Chart it works exactly the same as in other chart types,
112
with the exception that `dataLoader` is set as a property to the data set
113
definition. I.e.:
114
 
115
```
116
var chart = AmCharts.makeChart("chartdiv", {
117
  "type": "stock",
118
  ...
119
  "dataSets": [{
120
    "title": "MSFT",
121
      "fieldMappings": [{
122
        "fromField": "Open",
123
        "toField": "open"
124
      }, {
125
        "fromField": "High",
126
        "toField": "high"
127
      }, {
128
        "fromField": "Low",
129
        "toField": "low"
130
      }, {
131
        "fromField": "Close",
132
        "toField": "close"
133
      }, {
134
        "fromField": "Volume",
135
        "toField": "volume"
136
      }],
137
      "compared": false,
138
      "categoryField": "Date",
139
      "dataLoader": {
140
        "url": "data/MSFT.csv",
141
        "format": "csv",
142
        "showCurtain": true,
143
        "showErrors": true,
144
        "async": true,
145
        "reverse": true,
146
        "delimiter": ",",
147
        "useColumnNames": true
148
      }
149
    }
150
  }]
151
});
152
```
153
 
154
### Can I also load event data the same way?
155
 
156
Sure. You just add a `eventDataLoader` object to your data set. All the same
157
settings apply.
158
 
159
 
160
## Adding custom headers to HTTP requests
161
 
162
If you want to add additional headers to your data load HTTP requests, use
163
"headers" array. Each header is an object with two keys: "key" and "value":
164
 
165
```
166
"dataLoader": {
167
  "url": "data/serial.json",
168
  "format": "json",
169
  "headers": [{
170
    "key": "x-access-token",
171
    "value": "123456789"
172
  }]
173
}
174
```
175
 
176
 
177
## Manually triggering a reload of all data
178
 
179
Once chart is initialized, you can trigger the reload of all data manually by
180
calling `chart.dataLoader.loadData()` function. (replace "chart" with the actual
181
variable that holds reference to your chart object)
182
 
183
## Using callback functions
184
 
185
Data Loader can call your own function when certain event happens, like data
186
loading is complete, error occurs, etc.
187
 
188
To set custom event handlers, use these config options:
189
 
190
* "complete"
191
 
192
Example:
193
 
194
```
195
AmCharts.makeChart( "chartdiv", {
196
  ...,
197
  "dataSets": [{
198
    ...,
199
    "dataLoader": {
200
      "url": "data.json",
201
      "load": function ( options, chart ) {
202
        console.log( 'Loaded file: ' + options.url );
203
      },
204
      "complete": function ( chart ) {
205
        console.log( 'Woohoo! Finished loading' );
206
      },
207
      "error": function ( options, chart ) {
208
        console.log( 'Ummm something went wrong loading this file: ' + options.url );
209
      }
210
    }
211
  }]
212
} );
213
```
214
 
215
 
216
## Translating into other languages
217
 
218
Depending on configuration options the plugin will display a small number of
219
text prompts, like 'Data loading...'.
220
 
221
Plugin will try matching chart's `language` property and display text prompts in
222
a corresponding language. For that the plugin needs to have the translations.
223
 
224
Some of the plugin translations are in **lang** subdirectory. Simply include the
225
one you need.
226
 
227
If there is no translation to your language readily available, just grab en.js,
228
copy it and translate.
229
 
230
The structure is simple:
231
 
232
```
233
'The phrase in English': 'Translation'
234
```
235
 
236
The phrase in English must be left intact.
237
 
238
When you're done, you can include your language as a JavaScript file.
239
 
240
P.S. send us your translation so we can include it for the benefits of other
241
users. Thanks!
242
 
243
 
244
## Requirements
245
 
246
This plugin requires at least 3.13 version of JavaScript Charts, JavaScript
247
Stock Chart or JavaScript Maps.
248
 
249
 
250
## Demos
251
 
252
They're all in subdirectory /examples.
253
 
254
 
255
## Extending this plugin
256
 
257
You're encouraged to modify, extend and make derivative plugins out of this
258
plugin.
259
 
260
You can modify files, included in this archive or, better yet, fork this project
261
on GitHub:
262
 
263
https://github.com/amcharts/dataloader
264
 
265
We're curious types. Please let us know (contact@amcharts.com) if you do create
266
something new out of this plugin.
267
 
268
 
269
## License
270
 
271
This plugin is licensed under Apache License 2.0.
272
 
273
This basically means you're free to use or modify this plugin, even make your
274
own versions or completely different products out of it.
275
 
276
Please see attached file "license.txt" for the complete license or online here:
277
 
278
http://www.apache.org/licenses/LICENSE-2.0
279
 
280
 
281
## Contact us
282
 
283
* Email:contact@amcharts.com
284
* Web: http://www.amcharts.com/
285
* Facebook: https://www.facebook.com/amcharts
286
* Twitter: https://twitter.com/amcharts
287
 
288
 
289
## Changelog
290
 
291
### 1.0.8
292
* Added "headers" config variable which allows adding custom headers to HTTP requests
293
 
294
### 1.0.7
295
* Fixed an issue with the Pie chart when it is being loaded in inactive tab
296
 
297
### 1.0.6
298
* Added support for Gauge chart (loads "arrows" array)
299
 
300
### 1.0.5
301
* Fixed JS error if periodSelector was not defined in chart config
302
* Now all callback functions (complete, error, load) receive additional parameter: chart
303
* postProcess function will now have "this" context set to Data Loader object as well as receive chart reference as third paramater
304
 
305
### 1.0.4
306
* Added chart.dataLoader.loadData() function which can be used to manually trigger all data reload
307
 
308
### 1.0.3
309
* Fixed the bug where defaults were not being applied properly
310
* Fixed the bug with translations not being applied properly
311
* Cleaned up the code (to pass JSHint validation)
312
 
313
### 1.0.2
314
* Fixed the issue with modified Array prototypes
315
 
316
### 1.0.1
317
* Added "complete", "load" and "error" properties that can be set with function handlers to be invoked on load completion, successful file load or failed load respectively
318
* Fixed language container initialization bug
319
* Fixed bug that was causing parse errors not be displayed
320
 
321
### 1.0
322
* Added GANTT chart support
323
 
324
### 0.9.2
325
* Added global data load methods that can be used to load and parse data by code outside plugin
326
* Trim CSV column names
327
* Translation added: Lithuanian
328
 
329
### 0.9.1
330
* Fix chart animations not playing after asynchronous load
331
 
332
### 0.9
333
* Initial release