Can I render multiple charts by single renderfunction call in ZingChart?

被刻印的时光 ゝ 提交于 2019-12-12 12:12:24

问题


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
  });

Thanks in advance.


回答1:


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);


来源:https://stackoverflow.com/questions/39786277/can-i-render-multiple-charts-by-single-renderfunction-call-in-zingchart

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!