
Extending the data renderer
The IT department e-mailed us while we were working on our chart. They created some data feeds for us to pull the social media conversion numbers that we need. We are going to create a scatterplot with the total number of daily shares on Twitter and the total conversions. The new data source returns an array so we won't need to change anything.
Our original remoteDataSource
function was tailored specifically for our other social media chart. We decide to extract the functionality to retrieve remote data and also make use of dataRendererOptions
.
To start off, we create a new file called functions.js
inside our js
folder. We will save our new function, remoteDataCallback
, in this file so we can reuse the code.
We remove the code that parsed the JSON object. In its place, we assign options.dataCallback
to our data
array. Later, when we create our chart, we will pass a function called dataConversion
into dataCallback
. We pass remoteData
, which is the JSON object, as a parameter to our dataCallback
method:
var remoteDataCallback = function(url, plot, options) {
var data = new Array;
$.ajax({
async: false,
url: url,
dataType:"json",
success: function(remoteData) {
data = options.dataCallback(remoteData);
}
});
return data;
};