duanmen8491 2018-11-27 20:46
浏览 115

使用JSON填充Highcharts数据

I have been running a few Highcharts on my website. Previously, I populated these with data from my $result array. Below is an example of code for how I would first push several series of data into the $result array and then import it into the Highcharts embed.

$result array is created in variables.php:

$result = array();
array_push($result,$xAxis);                             
array_push($result,$yAxis);                                 
print json_encode($result, JSON_NUMERIC_CHECK);

$result data is set into the Highcharts embed in a separate php file:

var tableName = '<?php echo $tableName; ?>'
$.getJSON("../data/variables.php", {id: escape(tableName)}, function(json) {
    chartOptions.chart1.xAxis.categories = json[0]['data'];
    chartOptions.chart1.series[0].data = json[1]['data'];
});

Because I now have to create many different charts, I changed how I make the $result array and now use a loop instead ($result array is now renamed to $compData). This works just fine and all the data I need is captured in $compData using this new setup. However, I don't understand how I can now set data into the Highcharts embed with this new setup of the $compData array. I tried using the 'print json_encode($compData, JSON_NUMERIC_CHECK);' but this doesn't work. I would very much appreciate if anyone can help me with this.

To summarise: the code below works just fine but I am trying to understand how I can input data from the $compData array into my Highcharts.

foreach($idArray as $val) {
    $data = [];
    $sth->bind_param("s", $val);
    $sth->execute();
    $result = $sth->get_result();
    while ($r = $result->fetch_array()) {
        $data = array_merge($data, array_splice($r, 2, $CI_NOYEARS));
    }
    $compData[$val]["data"] = $data;
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 shape_predictor_68_face_landmarks.dat
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 对于相关问题的求解与代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料
    • ¥15 使用R语言marginaleffects包进行边际效应图绘制