我正在尝试使用 Envision.js 为数据图表组件创建一个 Web 应用程序。所使用的数据是 JSON 格式的股票价格代码提要。我已经使用 ajax jquery 调用形成了一个标准财务折线图(Envision Finance 模板),用于获取股票数据并在 XY 轴上应用数据。
但要求是创建一个实时图表,该图表将随时间自动更新带有所有子图表详细信息的股票数据。以下是股票图表应用程序的代码:
(function ajax_demo (container) {
// Get initial data
$.getJSON('static/stockTicker.json', function (initialData) {
var
currentData = initialData,
options, finance;
options = {
container : container,
data : {
price : currentData.price,
volume : currentData.volume,
summary : currentData.summary
},
trackFormatter : function (o) {
var
index = o.index,
value;
value = currentData.data[index].date + ': $' + currentData.price[index][1] + ", Vol: " + currentData.volume[index][1];
return value;
},
// An initial selection
selection : {
data : {
x : {
min : 0,
max : 250
}
}
},
// Override some defaults.
// Skip preprocessing to use flotr-formatted data.
defaults : {
volume : {
skipPreprocess : true
},
price : {
skipPreprocess : true
},
summary : {
skipPreprocess : true,
config : {
xaxis : {
// Set x ticks manually with defaults override:
ticks : currentData.summaryTicks
}
}
}
}
};
// Set the selection callback:
options.selectionCallback = (function () {
var data = {
initial : initialData,
fetched : null
};
// Helper for fetching high resolution data
function fetchData (o) {
$.getJSON('static/stockSample.json', function (fetchedData) {
data.fetched = fetchedData;
currentData = fetchedData;
finance.price.options.data = data.fetched.price;
finance.volume.options.data = data.fetched.volume;
_.each(finance.selection.followers, function (follower) {
follower.trigger('zoom', o);
}, this);
});
}
// Selection callback:
return function (selection) {
if (finance) {
var
x = selection.data.x;
if (x.max !== null && Math.abs(x.max - x.min) < 250) {
if (data.fetched) {
// Use high resolution data, if available
finance.price.options.data = data.fetched.price;
finance.volume.options.data = data.fetched.volume;
currentData = data.fetched;
} else {
// Fetch high resolution data
fetchData(selection);
}
} else {
// Use low resolution data
finance.price.options.data = data.initial.price;
finance.volume.options.data = data.initial.volume;
currentData = data.initial;
}
}
}
})();
finance = new envision.templates.Finance(options);
});
}
)(document.getElementById("Demo"));
我找不到任何可以将 Envision.js 中的股票图表与随特定时间更新的动态股票价格数据集成的示例。我应该使用 Spring mvc 还是普通的 servlet 让它工作?
请帮忙!