Dynamically populate series on a date chart

1,153 views
Skip to first unread message

AcadiaSolutions

unread,
Oct 1, 2009, 1:43:04 PM10/1/09
to jqplot-users
First, I am new to jQuery and jqPlot - so I need some basic help.
Thanks to anyone responding quickly.

x-axis is dates, y is numbers. the data values and number values are
generated automatically. When I pass the variable to the series in
the $.jqplot, I get an error. Yet, if I type it directly as:

line1=[['2009-10-01',15], ['2009-09-30',35], ['2009-09-29',98]];

it works fine, but, if set a variable to dynamically gather the data
then pass it, it fails

var jn = "[" + gatheredValues + "]";

line1=jn;

Not sure how to do this - really need some help. Want to use jqPlot,
but not understanding fully how it works.

Mike K

Mark Daggett

unread,
Oct 1, 2009, 2:18:03 PM10/1/09
to jqplot...@googlegroups.com
If this dynamically created data is coming from a string of values you
can do

var data = new Array(myCommaDelimitedString)

That should give you an actual array instead of a string

Sent from my iPhone

On Oct 1, 2009, at 12:43 PM, AcadiaSolutions <mki...@acadiasolutions.com
Message has been deleted

AcadiaSolutions

unread,
Oct 1, 2009, 3:08:24 PM10/1/09
to jqplot-users
Thanks again Mark,

Since I had a delimited string, I used split to get an array, and then
tried to pass the $.jqplot function the arrayname in square brackets.
This is a dateAxis, so the array members are ['2009-10-01',5].

some of the code is as follows, but is still does not work.

var seriesArray = jn.split(";");

// line1=[['2009-10-01',5], ['2009-09-30',20], ['2009-09-29',98]];

plot9 = $.jqplot('chart1', [[seriesArray]], {

if I were to uncomment the 'line1' reference, and replace
[[seriesArray]] with [line1], it works fine. the values in the
seriesArray looks just like line 1, only not surrounded by brackets.
can you see anything I am missing?

Thanks
Mike K

On Oct 1, 2:18 pm, Mark Daggett <heavysi...@gmail.com> wrote:
> If this dynamically created data is coming from a string of values you  
> can do
>
> var data = new Array(myCommaDelimitedString)
>
> That should give you an actual array instead of a string
>
> Sent from my iPhone
>
> On Oct 1, 2009, at 12:43 PM, AcadiaSolutions <mkin...@acadiasolutions.com

John L. Cheng

unread,
Oct 2, 2009, 11:36:28 AM10/2/09
to jqplot-users
line1 is a 2 dimensional array. The JS split will only create a 1-D
array.

Maybe something like this:

var foo = new Array();
var jnSplit1 = "2009-10-01|05,2009-09-30|20".split(",");
for ( var i = 0; i < jnSplit1.length; i++) {
foo.push( jnSplit1[i].split("|"))
};

Note that foo is delimited by both pipe (|) and comma(,) to create a
2D
array.

On Oct 1, 12:08 pm, AcadiaSolutions <mkin...@acadiasolutions.com>
wrote:
Message has been deleted

AcadiaSolutions

unread,
Oct 2, 2009, 12:36:41 PM10/2/09
to jqplot-users
Thanks to Mark and John. I was able to figure it out. I was (without
realizing it I guess) submitting the [] around each 2d array I was
passing
to line1.

Once I figured this out, I was able to get it to work. The chart
looks
great. Looking forward to making the others. Really like jqplot.

Thanks.
Michael Kinder

Miss Shee

unread,
Nov 21, 2012, 7:33:22 AM11/21/12
to jqplot...@googlegroups.com
Hi
I have the same problem here 
I have a bar chart, and I cant get it to work
It only renders the grid.
Can any one please tell me what am I missing here?

           
            var data = $('.lblX').text() + ',' + $('.lblY').text();
           //data is : 10000|2881000|22497000|24826200|26579000|16554000|39650000,2550000|2017000|9924000|13150000|3582100|9714000|9951000
            var ticks = ['Saturday', 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'];
            var dataArray = new Array();
            var commaSplited = data.split(",");

            for (var i = 0; i < commaSplited .length; i++) {
                dataArray.push([commaSplited [i].split("|")])
            }

            var plot1 = $.jqplot('chart1', [dataArray], {

                seriesDefaults: {
                    pointLabels: { show: true },
                    renderer: $.jqplot.BarRenderer,
                    rendererOptions: { fillToZero: true }
                },
                series: [
                 { label: 'X' },
                 { label: 'Y' }
                 ],
                legend: {
                    show: true,
                    placement: 'outsideGrid'
                },
                axes: {
                    xaxis: {
                        renderer: $.jqplot.CategoryAxisRenderer,
                        ticks: ticks
                    },

                yaxis: {
                        pad: 1.05
                        , tickOptions: { formatString: '%d' }
                    }
                }
            });



Miss Shee

unread,
Nov 24, 2012, 4:25:28 PM11/24/12
to jqplot...@googlegroups.com
I found the problem, I parsed the elements before push !!!
parseInt :)
Reply all
Reply to author
Forward
0 new messages