score:2

Accepted answer

The problem is your query.

It should be like the following.

SELECT x_axis, y_axis FROM yourTableName;

This way you'll get exactly the format that Highcharts needs. You just have to insert it inside an array.

score:0

probably array combine and than json encode and replace? just in case for diversity;)

<?php 

$x_axis = array(
'Safari', 'Opera', 'fireFox'
);

$y_axis = array(
10, 30.4, 50
);

$keyFilled = array_combine($x_axis, $y_axis);

arsort($keyFilled);

$jsonData = json_encode($keyFilled);

$jsonDataReplaced = str_replace(array(',', '{', '}', ':'), array('],[', '[', ']', ','), $jsonData);
echo '<pre>';
var_dump('['.$jsonDataReplaced.']');

?>

output is:

string(45) "[["fireFox",50],["Opera",30.4],["Safari",10]]"

http://phpfiddle.org/main/code/jq4-cgb

score:1

[<? echo "'". json_encode($x_axis). "', " . json_encode($y_axis) ?>]

Demo: http://codepad.org/G5JAtXWu

Nix that I was confused.

What you want to do is this:

foreach($x_axis as $key=>$x) {
    echo "['" . $x . "', " . $y_axis[$key] . "]";
}

Demo: http://codepad.org/SKNk1VaX

To wrap it all up:

$d = array();
foreach($x_axis as $key=>$x) {
    $d[] = "['" . $x . "', " . $y_axis[$key] . "]";
}
echo json_encode($d);

Demo: http://codepad.org/KhofwXCi

score:1

Assuming:

$x_axis = array('Safari', 'Opera', 'Firefox', 'IE', 'Chrome', 'Others');
$y_axis = array(10, 6, 40.5, 20, 10.6, 0.5);

This should work:

$data = array();
$length = count($x_axis);
for ($i = 0; $i < $length; $i++) {
    $data[] = array($x_axis[i], $y_axis[i]);
}

Related Query

More Query from same tag