- Learning jqPlot
- Scott Gottreu
- 204字
- 2021-09-03 09:49:44
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;
};
- Mastering JavaScript Object-Oriented Programming
- Python自然語言處理實戰(zhàn):核心技術(shù)與算法
- 跟“龍哥”學(xué)C語言編程
- Unity 2020 Mobile Game Development
- 程序員數(shù)學(xué):用Python學(xué)透線性代數(shù)和微積分
- Mastering matplotlib
- Java 11 Cookbook
- Python貝葉斯分析(第2版)
- Hands-On Functional Programming with TypeScript
- Mastering Unity 2D Game Development(Second Edition)
- 0 bug:C/C++商用工程之道
- Java Web從入門到精通(第3版)
- 后臺開發(fā):核心技術(shù)與應(yīng)用實踐
- Improving your Penetration Testing Skills
- JavaScript程序設(shè)計基礎(chǔ)教程(慕課版)