问题描述
我访问了 ZingChart的文档,并通过调用多个渲染函数了解渲染多个图表的方法。
I visited ZingChart's documentation and came to know the methods of rendering multiple charts by calling multiple render functions like this.
zingchart.render({
id:'chartDiv1',
data:myChart1,
height:300,
width:500
});
zingchart.render({
id:'chartDiv2',
data:myChart2,
height:300,
width:500
});
zingchart.render({
id:'chartDiv3',
data:myChart3,
height:300,
width:500
});
zingchart.render({
id:'dashboardDiv',
data:myDashboard,
height:500,
width:700
});
但在我的代码中,我想编写较少的代码
But in my code I want to write less code which should work more for me as its also directed by my boss.
因此我的问题是我可以通过调用一个渲染函数来渲染多个图表?
有些事情:
So my question is Can I render multiple charts by just calling one render function?some thing like:
zingchart.render({
id:{'chartDiv1','chartDiv2','chartDiv3','chartDiv4'},
data:{myChart1,myChart2,myChart3,myChart4},
height:300,
width:500
});
提前感谢。
推荐答案
完全公开,我是ZingChart团队的成员。
Full disclosure, I'm a member of the ZingChart team.
我们目前不支持上面的示例代码,
We currently do not support the example code above but there are a couple ways you could do this with javascript.
function renderZingCharts(_id,_data) {
zingchart.render({
id: _id,
data: _data,
height:300,
width:500
});
}
renderZingCharts('chartDiv1', myChart1);
renderZingCharts('chartDiv2', myChart2);
renderZingCharts('chartDiv3', myChart3);
renderZingCharts('chartDiv4', myChart4);
如果要保留数组内容,也可以循环。
You Could also loop through if you want to keep the array content.
function renderZingCharts(aIds, aData) {
// do some sanity checks for length of two arrays here ???
for (var i=0; i < aIds.length; i++) {
zingchart.render({
id: aIds[i],
data: aData[i],
height:300,
width:500
});
}
}
var ids = ['chartDiv1', 'chartDiv2', 'chartDiv3', 'chartDiv4'];
var configs = [myChart1, myChart2, myChart3, myChart4];
renderZingCharts(ids,configs);
这篇关于我可以在ZingChart中通过单个renderfunction调用来呈现多个图表吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!