I need to add series to chart at the runtime.
I know how to do it in constructor but I need to create a chart and the add series to them. I didn't find a method like addSeries . Please, anybody knows what method do I need?
Printable View
I need to add series to chart at the runtime.
I know how to do it in constructor but I need to create a chart and the add series to them. I didn't find a method like addSeries . Please, anybody knows what method do I need?
It is probably best to remove the chart and add a new chart configured the way you want.
I'm going to agree with both the OP and with Mitchell. An "addSeries" method would be nice (maybe this should be a feature request). But in the meantime, I've used the solution suggested by Mitchell: removed the chart and added back re-configured as needed.
You could also do "chart.series.add()", followed by "chart.refresh()" - I've used that before for adding new series to charts. E.g.
Code:chart.series.add({
type: 'line',
axis: 'left',
xField: 'name',
yField: 'data4'
});
chart.refresh();
Well this might have saved a lot of time for me (actually the company I'm freelancing for) on a project I was working on earlier this spring/summer, but for the fact that chart.series.add is *not* documented; see:
http://docs.sencha.com/ext-js/4-0/#!....series.Series
Since Ext.chart.series extends from Ext.Base and not Ext.container.Container it didn't strike me I could call add()
agreed that it is a bit hidden :)
take a look at:
http://docs.sencha.com/ext-js/4-0/so...xt-chart-Chart
-> initComponent
-> this.series is an Ext.util.MixedCollection (this points to the chart itself), this is why add works here. There are no listeners bound to the collection (like refresh chart on add, remove etc.), so therefore the manual call. would be a reasonable feature request tough :)Code:series = me.series;
me.series = Ext.create('Ext.util.MixedCollection', false, function(a) { return a.seriesId || (a.seriesId = Ext.id(null, 'ext-chart-series-')); });
if (series) {
me.series.addAll(series);
}
best regards
tobiu
Thanks for acknowledging that this could constitute a reasonable feature request. In the meantime though, shouldn't it be considered a documentation bug?