germaintanon / flot

Automatically exported from code.google.com/p/flot
MIT License
0 stars 0 forks source link

set flot options via AJAX #678

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I am using Flot for charting. Because the chart types are many in the app I'am 
creating, I use dynamic generated SQL queries (through PHP) and the resulted 
series are dynamic. I have managed to set almost every setting of Flot by 
sending php array through php's json_encode to flot and everything was ok until 
I tried to position 3 yaxis on "left" and "right". Here is the PHP code I use 
(yaxis part only):
$data['options']['yaxis'][1]['position']='left';
$data['options']['yaxis'][2]['position']='left';
$data['options']['yaxis'][3]['position']="right";

and here is the ajax request:
$.ajax({
        url: "../ajax.php",
        data: vars,
        type: 'POST',
        dataType: 'json'
    }).done(function(data){
        $.plot(placeholder, data['data'], data['options']);
        tooltips(placeholder);
    });

As you can see I am loading "options" element of the "data" array as options, 
but the flot doesn't recognize the settings set for each yaxis. If I set the 
index of the yaxis to 0 (ex. $data['options']['yaxis'][0]['position']='right';) 
all yaxis are going to the right side of the chart.

Could someone put some light here?

Original issue reported on code.google.com by vihren.k...@gmail.com on 18 Mar 2012 at 9:17

GoogleCodeExporter commented 8 years ago
Change it to solved!

I have found the solution. When creating dynamic content charts with PHP you 
have full control on settings. Just keep in mind the type of the different 
elements in the options object/array. In my case I was always using arrays and 
the script (FLOT) didn't read them correctly (better said: I didn't write them 
correctly). After I read all the options in the JS file I found that I must use 
objects instead of arrays and now I have "full control" over flot options 
through PHP.

P.S. The array/object with the options and data is send to flot with json.

Original comment by vihren.k...@gmail.com on 20 Mar 2012 at 7:34

GoogleCodeExporter commented 8 years ago

Original comment by dnsch...@gmail.com on 30 Apr 2012 at 12:35