I'm trying to do the following: Get some data from the backend and bind it with a JQplot candlestick chart.
What i've accomplished:
- The data is being generated in the backend
- The data is being procured by using the $.get() function of jQuery.
So heres the problem:
The data , if i bind it to a variable by doing:
CASE I_
ohlc = [['2011-01-03 09:30:00',325.7,325.99,324.82,325.39],['2011-01-03 09:35:00',325.44,326.74,325.4,326.46],['2011-01-03 09:40:00',326.54,327.38,326.38,327.23]];
It works like a breeze.
But when i use
CASE II_
$.get('MYSERVLET', function(data){
ohlc = data;
});
and the chart is generated , i get an error at the console saying:
Uncaught #<Object>
init
w.jqplot
(anonymous function)
jQuery.event.handle
jQuery.event.add.elemData.handle.eventHandle
Also when i do a console.log in CASE I , i get them as arrays. But in CASE II , it looks like normal data . I dont know if thats of any help but i noticed this.
Does anyone know how to fix this? What am i doing wrong?
For jqplot the data has to be in array form. You probably have to check what is the format of data you are getting in case 2. If it is not in array format then inside the $.get function you may have to write some custom code which will convert it into array format.
EDIT:
The array similar to 1st case can be generated using 2 for loops
And as Shortstick suggested the chart has to be drawn only after the data is returned from the get method.