官术网_书友最值得收藏!

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;
};
主站蜘蛛池模板: 平度市| 莱芜市| 多伦县| 集安市| 双桥区| 平山县| 舒兰市| 荥阳市| 溧阳市| 广安市| 关岭| 静乐县| 桃江县| 桃源县| 罗城| 依兰县| 武清区| 遂平县| 通江县| 辛集市| 小金县| 兴仁县| 罗平县| 顺平县| 宕昌县| 正安县| 讷河市| 南宁市| 乌恰县| 延津县| 惠州市| 弥勒县| 大余县| 南投市| 新化县| 额济纳旗| 濮阳市| 浦东新区| 华亭县| 深水埗区| 响水县|