Retrieving Data

FusionCharts API includes several methods that allow you to fetch real-time data from drag-able charts.

In this section, you will be shown how you can:

  • Retrieve a data set in the JSON format

  • Retrieve a data set in the XML format

  • Retrieve a data set in the CSV format

  • Retrieve data using the getDataWithID() method

  • Retrieve data using the getData() method

Retrieving a Data Set in the JSON Format

A drag-able column 2D chart configured to retrieve JSON data and render it in an alert window looks like this:

FusionCharts should load here..

Given below is a brief description of the function used to retrieve JSON data:

Function Name Description
getJSONData It is used to fetch data that has been set on a chart in the JSON format. This function needs to be called on an existing chart. If this function is called on a chart which has no data set on it, it returns an empty { } object.

The data structure needed to retrieve data set in the JSON format is given below:

...

Retrieving a Data Set in the XML Format

Given below is a brief description of the function used to retrieve XML data:

Function Name Description
getXMLData It is used to fetch data that has been set on a chart in the XML format. This function needs to be called on an existing chart. If this function is called on a chart which has no data set on it, it returns an empty <chart /> element as string.

Retrieving a Data Set in the CSV Format

Given below is a brief description of the function used to retrieve CSV data:

Function Name Description
getCSVData It is used to fetch data that has been set on a chart in the CSV format. The data returned is the closest possible comma-separated value representation that has been provided to the chart. The exported data does not contain any functional or cosmetic attribute that was set on the chart.

Retrieving Data Using the getDataWithID() Function

The getDataWithID() function returns a three-dimensional array that contains the data and the dataset IDs. Once the reference for the chart is obtained, this function can be invoked to retrieve data.

A drag-able column chart configured to retrieve data using the getDataWithID() function looks like this:

FusionCharts should load here..

The data returned by the getDataWithID() function is without any editing.

The key pointers of this method are:

  • [0,0] index of the array is empty

  • The first row in the array returned contains the series name of each dataset placed horizontally (sequentially)

  • The first column in the array returned contains the labels of all the categories

  • The remaining columns map to their respective category and dataset. For each data, its id and last updated value on the chart is returned. In our example, because we have not changed any data visually on the chart, it is showing the original data.

Given below is the structure of the three-dimensional array returned by this function:

[0,0] - Empty [0,1]- Dataset id [0,2] - Dataset Id [0,n]- Dataset Id
[1,0] - Category label of data index 1 Data for dataset [1] data index [1] - returned as an array with two elements. Sub array [0] - Id of set Sub array [1] - Updated value of set Data for dataset [2] data index [1] - returned as an array with two elements. Sub array [0] - Id of set Sub array [1] - Updated value of set Data for dataset [n] data index [m] - returned as an array with two elements. Sub array [0] - Id of set Sub array [1] - Updated value of set
[2,0] - Category label of data index 2 Data for dataset [1] data index [2] - returned as an array with two elements. Sub array [0] - Id of set Sub array [1] - Updated value of set Same as above Same as above
[m,0] - Category label of data index m Data for dataset [n] data index [m] - returned as an array with two elements. Sub array [0] - Id of set Sub array [1] - Updated value of set Same as above Same as above

The data structure needed to retrieve data using the getDataWithID() function is given below:

...

Retrieving Data Using the getData() Function

The getData() function is similar to the getDataWithID() function except that it returns just the updated value of the data on the chart and not its ID.

Thus, the array returned by the getData() function is a two-dimensional array where each data cell contains just the numeric value representing the final value of the data on the chart.

A drag-column chart configured to retrieve data using the getData() method looks like this:

FusionCharts should load here..

The data structure needed to retrieve data using the getData() method is given below:

...

There! You have now seen how you can retrieve data from drag-able charts.