1

我从服务器获取正确的 JSON 对象数组并将其分配给系列。chart_cfd.series 还在调试器中显示正确的对象,但图表绘制没有发生。

这里可能是什么问题?我需要更改数组成员的类型吗?

注意:如果我在 javascript 中本地提供系列数据,图表会完美填充(简单列类型)

Javascript:(我正在使用 highcharts 框架)

//series = [] 在图表对象中

function requestCFDStatusData(){

  $.post(
     'ajax/cfdUtil/cfd_status.php',

 function(response){
                       chart_cfd.series = response;
                       });
}

PHP 代码

<?php
header("Content-type: text/json");
$cfdData = array(
    array(
'name' => 'A',
'data' => array(49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4,22,34,23,11)),
    array(
'name' => 'B',
'data' => array(83.6, 78.8, 98.5, 93.4, 106.0, 84.5, 105.0, 104.3, 91.2, 83.5, 106.6, 92.3,22,50,34,11)),
    array(
'name' => 'C',
'data' => array(48.9, 38.8, 39.3, 41.4, 47.0, 48.3, 59.0, 59.6, 52.4, 65.2, 59.3, 51.2,100,25,45,42)),
    array(
'name' => 'D',
'data' => array(42.4, 33.2, 34.5, 39.7, 52.6, 75.5, 57.4, 60.4, 47.6, 39.1, 46.8, 51.1,32,33,46,54)),
    array(
'name' => 'E',
'data' => array(48.9, 38.8, 39.3, 41.4, 47.0, 48.3, 59.0, 59.6, 52.4, 65.2, 59.3, 51.2,12,12,44,50)),
    array(
'name' => 'F',
'data' => array(48.9, 38.8, 39.3, 41.4, 47.0, 48.3, 59.0, 59.6, 52.4, 65.2, 59.3, 51.2,12,12,44,50)),
    array(
'name' => 'G',
'data' => array(48.9, 38.8, 39.3, 41.4, 47.0, 48.3, 59.0, 59.6, 52.4, 65.2, 59.3, 51.2,12,12,44,50)),
    array(
'name' => 'H',
'data' => array(48.9, 38.8, 39.3, 41.4, 47.0, 48.3, 59.0, 59.6, 52.4, 65.2, 59.3, 51.2,12,12,44,50)),
    array(
'name' => 'I',
'data' => array(48.9, 38.8, 39.3, 41.4, 47.0, 48.3, 59.0, 59.6, 52.4, 65.2, 59.3, 51.2,12,12,44,50)),
    array(
'name' => 'J',
'data' => array(48.9, 38.8, 39.3, 41.4, 47.0, 48.3, 59.0, 59.6, 52.4, 65.2, 59.3, 51.2,12,12,44,50)),
    array(
'name' => 'K',
'data' => array(48.9, 38.8, 39.3, 41.4, 47.0, 48.3, 59.0, 59.6, 52.4, 65.2, 59.3, 51.2,12,12,44,50))

);

$jsonEncoded = json_encode($cfdData);

echo $jsonEncoded;
?>

注意:如果我在 javascript 中本地提供,以下数据可以正常工作

series: [{
            name: 'A',
   data: [49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4,22,34,23,11]

        }, {
            name: 'B',
   data: [83.6, 78.8, 98.5, 93.4, 106.0, 84.5, 105.0, 104.3, 91.2, 83.5, 106.6, 92.3,22,50,34,11]

        }, {
            name: 'C',
   data: [48.9, 38.8, 39.3, 41.4, 47.0, 48.3, 59.0, 59.6, 52.4, 65.2, 59.3, 51.2,100,25,45,42]

        }, {
            name: 'D',
   data: [42.4, 33.2, 34.5, 39.7, 52.6, 75.5, 57.4, 60.4, 47.6, 39.1, 46.8, 51.1,32,33,46,54]

        },{
            name: 'E',
   data: [48.9, 38.8, 39.3, 41.4, 47.0, 48.3, 59.0, 59.6, 52.4, 65.2, 59.3, 51.2,12,12,44,50]

        },{
            name: 'F',
   data: [48.9, 38.8, 39.3, 41.4, 47.0, 48.3, 59.0, 59.6, 52.4, 65.2, 59.3, 51.2,12,12,44,50]

        },{
            name: 'G',
   data: [48.9, 38.8, 39.3, 41.4, 47.0, 48.3, 59.0, 59.6, 52.4, 65.2, 59.3, 51.2,12,12,44,50]

        },{
            name: 'H',
   data: [48.9, 38.8, 39.3, 41.4, 47.0, 48.3, 59.0, 59.6, 52.4, 65.2, 59.3, 51.2,12,12,44,50]

        },{
            name: 'I',
   data: [48.9, 38.8, 39.3, 41.4, 47.0, 48.3, 59.0, 59.6, 52.4, 65.2, 59.3, 51.2,12,12,44,50]

        },{
            name: 'J',
   data: [48.9, 38.8, 39.3, 41.4, 47.0, 48.3, 59.0, 59.6, 52.4, 65.2, 59.3, 51.2,12,12,44,50]

        },{
            name: 'K',
   data: [48.9, 38.8, 39.3, 41.4, 47.0, 48.3, 59.0, 59.6, 52.4, 65.2, 59.3, 51.2,12,12,44,50]

        }]
4

2 回答 2

2

在标头中使用内容类型作为 javascript

   header("Content-type: text/javascript");

然后使用 jquery 的 getJSON 方法作为

      $.getJSON('ajax/cfdUtil/cfd_status.php',function(response){
          chart_cfd.series = response;
                   });
于 2012-07-14T20:08:30.907 回答
1

可能是你应该application/json在你的php文件中使用,或者你可以使用text/plain然后你可以使用$.parseJSON

function requestCFDStatusData(){
    $.post('ajax/cfdUtil/cfd_status.php', function(response){
        chart_cfd.series = $.parseJSON(response);
    });
}

这可能对您有所帮助

于 2012-07-14T20:03:14.593 回答