我有许多剑道图表绘制到一页(每个图表是部分视图)。当它们全部渲染完后,我需要从中创建图像并将图像数据写入数据库。尽管所有的图表都被写入数据库,但其中一些图表没有数据,只有轴和图例等。
onRender
到
getKendoChart
但现在要明白这意味着
准备渲染
. 我只是在用
为海图收集身份证。
function onRender(e) { // "Fired when the chart is ready to render on screen."
var elementId = e.sender.element[0].id;
// e.g. chartTargetPrice43
var id = elementId.substring("chartTargetPrice".length); // 43
renderedCharts.push({ id: id }); //, chart: $('#' + elementId).getKendoChart() });
renderedTotal += 1;
}
exportImage
把它们保存到数据库中。完整功能如下,以供参考。
如何检查图表是否已完全呈现,而不必引入
setTimeout
function exportRenderedCompany(idArray) {
// idArray is an array, but could just have one element
var countRequests = idArray.length;
while (idArray.length > 0) {
var id = idArray.shift();
// renderedCharts.find(x => x.id == id)... IE11 does not recognise 'find', so
var foundChart;
for (var i = 0; i < renderedCharts.length; i++) {
if (renderedCharts[i].id == id) {
//foundChart = renderedCharts[i].chart;
foundChart = $('#chartTargetPrice' + id).getKendoChart();
break;
}
}
foundChart.exportImage({ width: 694, height: 250 }).done(function (data) {
// split 'image/png,xxxyyy=' into two
var dataParts = data.split(',', 2);
// TODO: need to strip from 'data:image/png;base64'
dataParts[0] = 'image/png';
$.ajax({
url: "@Url.Action("Export_TargetPrice", "Charts")",
type: 'POST',
data: { contentType : dataParts[0], base64 : dataParts[1], companyID: id }
}).done(function () {
countRequests--;
if (countRequests <= 0) {
window.location.href = "@Url.Action("Recommendations","Charts", new { page = page + 1 })#autoOnRender";
}
});
});
}
}