4

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 Answer 1

6

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);
1
  • 1
    I got your point, but i will suggest to keep this scenario in mind for your future updates, Thanks. Oct 1, 2016 at 10:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.