Addseries dynamically

I have some bar charts where I do not have fixed names for the series - eg I want to be able to create new departments and locations and produce a chart of the number of users per department at each location.

I wrote some code that fires on the XLE event for the chart which uses chart.get(chart.first()) to get the first row of content and loop through it to find the names of the series. I use
chart.addseries() to add each one dynamically still as part of the XLE event.

I was very pleased to be able to get this working successfully so my chart gets drawn correctly without me knowing the names of the departments or locations in advance. I even managed to get it to draw the legend dynamically as well…

now comes the problem -
this only works with “stackedBar” charts; all the other bar chart types produce a chart with axis but no content.
I tried a few things and it seems that a “stackedBar” can be created without content and then have all the series added afterwards but other chart types need to have the first series included when the object is created.

Can you help?

series should be added before data are loaded into a chart. If you are adding series dynamically, you should call render() method after:
barChart.addSeries({…});

barChart.addSeries({…});
barChart1.render();

I was using chart.refresh() I have changed to chart.refresh() but it does not change the outcome.

If I use stackedBar then I can add all the series dynamically.
Any other bar chart results in axis labelled correctly but an empty chart

Could you attach the complete demo that reproduces the problem ? Locally render() method has solved the problem