0

I am trying to extend an excellent HighCharts Column Range Chart example that I found at JSFiddle. After many days and lots of research I am almost done dynamically generating a my chart, except I cannot get the y data in the correct format for HighCharts.

I can successfully get the x data from the server in php to the browser in Javascript using json_encode, but I am stuck getting the y data to do the same, even after reading how to use json_encode and json_encode returning the next rows values - PHP PDO SQL HighCharts. I feel that I am on the cusp of the solution, but my computer thinks differently.

To simplify my problem solving I have hard-coded some example data in PHP:

$data_x_in_php_array = array();

// set x values
array_push($data_x_in_php_array, 'A');
array_push($data_x_in_php_array, 'B');

// set y values
$data_y_in_php_array[] = array('x' => 0, 'low' => 1375488000000, 'high' => 1375527600000);

Next I used json_encode to move the data from php to javascript:

var data_x_in_js_array =  <?php echo json_encode($data_x_in_php_array); ?>;
alert('data_x_in_js_array =' + data_x_in_js_array);

var data_y_in_js_array =  <?php echo json_encode($data_y_in_php_array, JSON_NUMERIC_CHECK); ?>;
alert('data_y_in_js_array =' + data_y_in_js_array);

I then commented out some of the data provided in the example and replaced it with the data_y_in_js_array:

var data_x =         data_x_in_js_array;

            data_y =             [{//blue
                                    data_y_in_js_array // uncommenting this line and commenting out the next three lines causes bars to disappear in the chart
                                    //x: 0,
                                    //low:  1375488000000, // milliseconds since unix epoch
                                    //high: 1375527600000  // milliseconds since unix epoch
                                 }

Unfortunately, the chart renders without displaying the bars.

I have posted an example at the excellent PhpFiddle. Any help is much appreciated.

Community
  • 1
  • 1
Beta
  • 11
  • 1
  • 4
  • Well for me " $data_y_in_php_array[] = array('x' => 0, 'low' => 1375488000000, 'high' => 1375527600000);" works properly. The problem with data_y_in_js_array is that it is array of strings not numbers in object. Generally it is not json. – Sebastian Bochan Apr 13 '15 at 08:54
  • Hmmm...when I go to line 100 of the PhpFiddle example, uncomment the data_y_in_js_array, and comment out the next three lines, like the last block of code, above, the bars do not show. Thank you for taking the time to look at this @SebastianBochan – Beta Apr 13 '15 at 13:52

1 Answers1

0

I got it to work! Using strtotime on the PHP side and finding out that month indexing starts at 0 (?!) in Javascript let to the solution that can be found here: PHP Fiddle.

Beta
  • 11
  • 1
  • 4