Json_encode之后的HighCharts列范围数据

时间:2015-04-12 18:18:41

标签: json highcharts

我正在尝试扩展我在JSFiddle找到的优秀HighCharts列范围图示例。经过多天和大量的研究,我几乎完成了动态生成我的图表,除了我无法以正确的HighCharts格式获取y数据。

我可以使用json_encode成功地从php中的服务器获取x数据到Javascript中的浏览器,但即使在阅读how to use json_encodejson_encode returning the next rows values - PHP PDO SQL HighCharts之后,我仍然无法获取y数据。 。我觉得我处在解决方案的尖端,但我的计算机有不同的想法。

为了简化我的问题解决,我在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);

接下来,我使用json_encode将数据从php移动到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);

然后我注释掉了示例中提供的一些数据,并将其替换为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
                                 }

不幸的是,图表呈现时没有显示条形图。

我在优秀的PhpFiddle发布了一个例子。非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

我得到了它的工作!在PHP端使用strtotime,并在Javascript中找到月份索引从0(?!)开始,让我们找到可在此处找到的解决方案:PHP Fiddle

相关问题