jquery_stack jquery_stack - 2 months ago 6x
PHP Question

PHP data to plot

I have the two arrays representing the x and y values but they just don't seem to be in the right format. I want to convert this:

Into something like this:

The code used for the first one is:

$dataset2[] = array(floatval($row["x"]),intval($row["y"]));

And for the second one is:

$dataset2[] = array(($x),($y));

In the second case I do have x and y as arrays of numbers and in the first case the mode of obtaining them is a bit different, and nope, unfortunately I can't just get the values as in the first case in the second one.

To convert it I use:

var dataset1 = <?php echo json_encode($dataset2); ?>;

In both cases. Thanks!


Try this ..

var a = floatval($row["x"]);
var b = intval($row["y"]);

for(var i = 0; i < a.length; i++){
    $dataset2[] = array(a[i],b[i]);