Hybrid View

  1. #1
    Sencha User
    Join Date
    Feb 2012
    Location
    Russia
    Posts
    30
    Vote Rating
    0
    vasily_87 is on a distinguished road

      0  

    Default 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?

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,547
    Vote Rating
    872
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    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
    ________________
    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 in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Mar 2009
    Location
    Fort Worth, TX
    Posts
    65
    Vote Rating
    -36
    jemptymethod is infamous around these parts jemptymethod is infamous around these parts jemptymethod is infamous around these parts jemptymethod is infamous around these parts jemptymethod is infamous around these parts

      0  

    Default


    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.

  4. #4
    Sencha - Sales Team daniel.gallo's Avatar
    Join Date
    Apr 2009
    Location
    Redwood City, CA
    Posts
    52
    Vote Rating
    9
    daniel.gallo will become famous soon enough

      0  

    Default


    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
    Sencha Inc.

  5. #5
    Sencha User
    Join Date
    Mar 2009
    Location
    Fort Worth, TX
    Posts
    65
    Vote Rating
    -36
    jemptymethod is infamous around these parts jemptymethod is infamous around these parts jemptymethod is infamous around these parts jemptymethod is infamous around these parts jemptymethod is infamous around these parts

      0  

    Default


    Quote Originally Posted by daniel.gallo View Post
    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()

  6. #6
    Sencha Premium Member tobiu's Avatar
    Join Date
    May 2007
    Location
    Munich (Germany)
    Posts
    2,695
    Vote Rating
    114
    tobiu is a name known to all tobiu is a name known to all tobiu is a name known to all tobiu is a name known to all tobiu is a name known to all tobiu is a name known to all

      0  

    Default


    agreed that it is a bit hidden

    take a look at:
    http://docs.sencha.com/ext-js/4-0/so...xt-chart-Chart

    -> initComponent

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


    best regards
    tobiu
    Best regards
    Tobias Uhlig
    __________

    S-CIRCLES Social Network Engine