Getting Selected Data

After you select a subset of data points in a select-scatter chart and click Submit, the selected data is sent to a server-side script, or a JavaScript function, for further processing.

In this section, you will be shown how the updated data is read using the JavaScript functions present on the same page.

After the chart is rendered, to access the chart data as an array, the following function is called:

1
2
3
4
5
//Get a reference to our chart
var chartObject= FusionCharts("chartId");    

//Now get the data as array. 
var arrData = chartObject.getData();

You first need to get a reference to the chart object. You can do so using the FusionCharts item reference method. Next, to get the data as an array, call the getData() method of the chart. This method returns the data of the chart in a two-dimensional array.

Given below is a brief description of the structure of this array:

[1,0] - Dataset 1 - This cell contains the dataset id Selected data point id for dataset 1 Selected data point id for dataset 1 Selected data point id for dataset 1 Selected data point id for this dataset…
[2,0] - Dataset 2 - This cell contains the dataset id Selected data point id for dataset 2 Selected data point id for dataset 2 Selected data point id for dataset 2 Selected data point id for this dataset...
[n,0] - Dataset n - This cell contains the dataset id Selected data point id for dataset n Selected data point id for dataset n Selected data point id for dataset n Selected data point id for this dataset...

Now, from this chart, if you select three data points from the Televisions dataset and five from the Cell Phones dataset and then return the data of chart as an array using the getData() method of the chart object, the tabular mapping of the array returned can be traced as under:

Televisions TV_1 TV_2 TV_3
Cell Phones Mob_1 Mob_2 Mob_3 Mob_4 Mob_5

If you map this with the JSON data, you will find the following:

  • Each dataset is returned as a single row in the array

  • The first column of each row contains the dataset index

  • The rest of the columns contain the ids of the selected points of that dataset

  • The length of each row's array (horizontally) can be different, depending on the number of data points chosen for that dataset

Reading JSON Data from the Chart

The chart also provides a method to read the selected data in the JSON/XML format. This method is named as the getJSONData() and can be invoked as under:

1
2
3
4
5
6
7
8
//Get a reference to our chart
var chartObject= FusionCharts("SelectChart"); 

//Get the data from chart 
var jsonRtn = chartObject.getJSONData();

//Show it to user in alert box
alert(jsonRtn);

The function getJSONData() returns the selected data. This function is also used to retrieve the complete data from the chart. To get the complete data from the chart you need to pass false as a parameter to the function. For example, var jsonRtn = chartObject.getJSONData(false);

A select-scatter chart configured to show how the selected data is retrieved and updated looks like this:

Vector imageLoading chart. Please wait

The data structure needed to configure the above chart is given below:

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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
{
   "chart": {
      "theme": "fint",
      "caption": "Products Sold vs. Price points",
      "subcaption": "Harry's SuperMart - Last Week",
      "yaxisname": "Quantity Sold",
      "xaxisname": "Price(In US $)",
      "xaxismaxvalue": "1000",
      "xaxisminvalue": "100",
      "yaxismaxvalue": "200",
      "xnumberprefix": "$",
      "ynumbersuffix": " units",
      "showcanvasborder": "1",
      "canvasborderthickness": "0.4",
      "canvasborderalpha": "50",
      "showXAxisLine": "0",
      "showformbtn": "1",
      "formAction": "#",
      "submitdataasxml": "1"
   },
   "categories": [
      {
         "verticallinecolor": "666666",
         "verticallinethickness": "1",
         "alpha": "40",
         "category": [
            {
               "label": "$100",
               "x": "100",
               "showverticalline": "0"
            },
            {
               "label": "$200",
               "x": "200",
               "showverticalline": "1"
            },
            {
               "label": "$300",
               "x": "300",
               "showverticalline": "1"
            },
            {
               "label": "$400",
               "x": "400",
               "showverticalline": "1"
            },
            {
               "label": "$500",
               "x": "500",
               "showverticalline": "1"
            },
            {
               "label": "$600",
               "x": "600",
               "showverticalline": "1"
            },
            {
               "label": "$700",
               "x": "700",
               "showverticalline": "1"
            },
            {
               "label": "$800",
               "x": "800",
               "showverticalline": "1"
            },
            {
               "label": "$900",
               "x": "900",
               "showverticalline": "1"
            },
            {
               "label": "$1000",
               "x": "1000",
               "showverticalline": "0"
            }
         ]
      }
   ],
   "dataset": [
      {
         "drawline": "0",
         "seriesname": "Televisions",
         "color": "#6baa01",
         "anchorsides": "3",
         "anchorradius": "4",
         "anchorbgcolor": "#6baa01",
         "anchorbordercolor": "#6baa01",
         "data": [
            {
               "id": "TV_1",
               "y": "559",
               "x": "714"
            },
            {
               "id": "TV_2",
               "y": "293",
               "x": "988"
            },
            {
               "id": "TV_3",
               "y": "231",
               "x": "970"
            },
            {
               "id": "TV_4",
               "y": "528",
               "x": "142"
            },
            {
               "id": "TV_5",
               "y": "95",
               "x": "800"
            },
            {
               "id": "TV_6",
               "y": "515",
               "x": "813"
            },
            {
               "id": "TV_7",
               "y": "444",
               "x": "928"
            },
            {
               "id": "TV_8",
               "y": "592",
               "x": "238"
            },
            {
               "id": "TV_9",
               "y": "229",
               "x": "959"
            },
            {
               "id": "TV_10",
               "y": "238",
               "x": "521"
            },
            {
               "id": "TV_11",
               "y": "285",
               "x": "222"
            },
            {
               "id": "TV_12",
               "y": "524",
               "x": "863"
            },
            {
               "id": "TV_13",
               "y": "422",
               "x": "820"
            },
            {
               "id": "TV_14",
               "y": "344",
               "x": "894"
            },
            {
               "id": "TV_15",
               "y": "510",
               "x": "800"
            },
            {
               "id": "TV_16",
               "y": "132",
               "x": "785"
            },
            {
               "id": "TV_17",
               "y": "381",
               "x": "214"
            },
            {
               "id": "TV_18",
               "y": "210",
               "x": "961"
            },
            {
               "id": "TV_19",
               "y": "496",
               "x": "575"
            },
            {
               "id": "TV_20",
               "y": "330",
               "x": "847"
            },
            {
               "id": "TV_21",
               "y": "436",
               "x": "893"
            },
            {
               "id": "TV_22",
               "y": "406",
               "x": "157"
            },
            {
               "id": "TV_23",
               "y": "125",
               "x": "349"
            },
            {
               "id": "TV_24",
               "y": "450",
               "x": "818"
            },
            {
               "id": "TV_25",
               "y": "455",
               "x": "615"
            },
            {
               "id": "TV_26",
               "y": "328",
               "x": "256"
            },
            {
               "id": "TV_27",
               "y": "188",
               "x": "460"
            },
            {
               "id": "TV_28",
               "y": "565",
               "x": "350"
            },
            {
               "id": "TV_29",
               "y": "149",
               "x": "582"
            },
            {
               "id": "TV_30",
               "y": "425",
               "x": "970"
            }
         ]
      },
      {
         "seriesname": "Cell Phones",
         "color": "#f8bd19",
         "anchorsides": "4",
         "anchorradius": "4",
         "anchorbgcolor": "#f8bd19",
         "anchorbordercolor": "#f8bd19",
         "data": [
            {
               "id": "Mob_1",
               "y": "335",
               "x": "156"
            },
            {
               "id": "Mob_2",
               "y": "339",
               "x": "927"
            },
            {
               "id": "Mob_3",
               "y": "328",
               "x": "847"
            },
            {
               "id": "Mob_4",
               "y": "1",
               "x": "177"
            },
            {
               "id": "Mob_5",
               "y": "246",
               "x": "175"
            },
            {
               "id": "Mob_6",
               "y": "368",
               "x": "441"
            },
            {
               "id": "Mob_7",
               "y": "146",
               "x": "200"
            },
            {
               "id": "Mob_8",
               "y": "347",
               "x": "482"
            },
            {
               "id": "Mob_9",
               "y": "1",
               "x": "463"
            },
            {
               "id": "Mob_10",
               "y": "63",
               "x": "440"
            },
            {
               "id": "Mob_11",
               "y": "77",
               "x": "211"
            },
            {
               "id": "Mob_12",
               "y": "108",
               "x": "824"
            },
            {
               "id": "Mob_13",
               "y": "44",
               "x": "850"
            },
            {
               "id": "Mob_14",
               "y": "77",
               "x": "712"
            },
            {
               "id": "Mob_15",
               "y": "15",
               "x": "199"
            },
            {
               "id": "Mob_16",
               "y": "333",
               "x": "836"
            },
            {
               "id": "Mob_17",
               "y": "31",
               "x": "482"
            },
            {
               "id": "Mob_18",
               "y": "90",
               "x": "604"
            },
            {
               "id": "Mob_19",
               "y": "294",
               "x": "716"
            },
            {
               "id": "Mob_20",
               "y": "241",
               "x": "870"
            },
            {
               "id": "Mob_21",
               "y": "258",
               "x": "421"
            },
            {
               "id": "Mob_22",
               "y": "186",
               "x": "456"
            },
            {
               "id": "Mob_23",
               "y": "255",
               "x": "327"
            },
            {
               "id": "Mob_24",
               "y": "203",
               "x": "995"
            },
            {
               "id": "Mob_25",
               "y": "35",
               "x": "792"
            }
         ]
      }
   ]
}
...

There! You have now seen how you can retrieve and update selected data from a select-scatter chart.