-
10 Jul 2012 4:45 AM #1
How to add series to chart
How to add series to chart
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?
-
16 Jul 2012 4:38 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,714
- Vote Rating
- 438
It is probably best to remove the chart and add a new chart configured the way you want.
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
2 Aug 2012 7:01 AM #3
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.
-
3 Aug 2012 12:13 AM #4
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();Daniel Gallo
Sales Engineer EMEA
Sencha UK Ltd
-
6 Aug 2012 9:22 AM #5
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()
-
10 Aug 2012 8:10 PM #6
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 toughCode: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
-
21 Aug 2012 7:30 AM #7
Thanks for acknowledging that this could constitute a reasonable feature request. In the meantime though, shouldn't it be considered a documentation bug?


Reply With Quote