PDA

View Full Version : Adding Series to Chart Dynamically



lukefowell89
30 Dec 2010, 4:35 AM
I have an array of column headers which I want to use in a chart series. The amount of these can vary so I need to dynamically add to the chart series for each of these headers. I am guessing this should be simple, but I am not sure how to do it.

Condor
30 Dec 2010, 4:43 AM
Just build your series object from the column info and call setSeries.

lukefowell89
31 Dec 2010, 1:10 AM
Is this how I should use this?


var chart_series = [];
for(var i = 1; i <= variables.length; i++)
{
//////////////////////////////////////
chart_series = series[i].yField = variables[i];
chart_series = series[i].type = 'column';
}
console.log(chart_series);
chart.setSeries(chart_series);

Condor
31 Dec 2010, 1:58 AM
No, that should be:

var chart_series = [];
for(var i = 1; i <= variables.length; i++){
chart_series.push({
yField: variables[i],
type: 'column'
});
}
chart.setSeries(chart_series);

delvia_bles
31 Dec 2010, 2:36 AM
its giving error "chart.setSeries" is not a function????

Please help.

steffenk
31 Dec 2010, 3:26 AM
make sure chart is referenced right.

delvia_bles
31 Dec 2010, 3:35 AM
i am using free version of Extjs. does that make a difference??

lukefowell89
31 Dec 2010, 3:42 AM
No, of course not! I didnt end up using setSeries as I had the same issue. But I used :-



var chart_series = [];
for(var i = 0; i <= variables.length-1; i++)
{
chart_series[i] = {
xField: variables[i],
type: 'bar',
displayName: variables[i]
}
}
chart.series = chart_series;

steffenk
31 Dec 2010, 3:43 AM
no. Debug your code, set a breakpoint on this lne and explore series and chart object. Make sure you have no extra comma or other incorrect things before. Or use console.log(chart) to explre the object. Hope you use firebug, you should be able to fix it fast.

just some seconds later - use setter functions only (setSeries, as Condor already suggested), changing properties is wrong as long you don't do other things.

delvia_bles
31 Dec 2010, 3:54 AM
Wow, thanks for all the help. I am trying out things and yes i use firebug but i wanted to know from where you guys find all these functions??? These are not defined anywhere in api document.

steffenk
31 Dec 2010, 4:00 AM
i mostly start with the docs finding methods, if there is nothing usable i open ext_all_debug.js in editor and search.
There you find setSeries which only does this:

setSeries : function(series){
this.series = series;
this.refresh();
}
you see that the refresh method is needed.

delvia_bles
31 Dec 2010, 4:37 AM
Thanks a ton! Its working absolutely fine.

Avillanueva
3 Jun 2011, 1:42 PM
Just build your series object from the column info and call setSeries.

Is there an example of this for version 4? I can't seem to get this to work.

Thanks!

jmitchell.br
25 Jul 2011, 6:21 PM
Yes - is this possible in extjs 4? The setSeries method seems to be gone...