Javascript 多系列数据线

Javascript 多系列数据线,javascript,php,json,highcharts,Javascript,Php,Json,Highcharts,我使用的查询结果显示3列(国家、日期、项目)。 我的php代码端 $res = db_query($sql); $dat = array(); while($r = db_fetch_array($res)){ $dat[]= array($r['date'], $r['items'], $r['country']); } // Armar $start_date = ''; if(count($dat)>0){ $s = split(' ',$dat[0][0]);

我使用的查询结果显示3列(国家、日期、项目)。 我的php代码端

 $res = db_query($sql);
$dat = array(); 
while($r = db_fetch_array($res)){
    $dat[]= array($r['date'], $r['items'], $r['country']);
}

// Armar
$start_date = '';
if(count($dat)>0){
    $s = split(' ',$dat[0][0]);
    $ss = split('-',$s[0]);
}
// Cada objeto en $dats es una grafica
$dats[] = array('type'=>'line',
            'name'=>$q['title'],
            'pointInterval'=>24 * 3600 * 1000,
            'pointStart'=>mktime(0,0,0,$ss[1],$ss[2],$ss[0])*1000,
            'data'=>$dat) ;
//echo "$sql";
echo json_encode($dats,JSON_NUMERIC_CHECK);
我的Javascript代码:

function loadLine(_data){
    $('#line_container').highcharts({
        chart: {zoomType: 'x',spacingRight: 20},
        title: { text: 'Monthly Created items'},
        subtitle: {text:'Updated every day'},
        xAxis: {
            type: 'datetime',
            maxZoom: 7 * 24 * 3600000, // fourteen days
            title: {text: null}
        },
        yAxis: {title: {text: 'Created items'}},
        tooltip: {shared: true},
        legend: {enabled: true},
        plotOptions: {
            area: {
                fillColor: {
                    linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1},
                    stops: [
                        [0, Highcharts.getOptions().colors[0]],
                        [1, Highcharts.Color(Highcharts.getOptions().colors[0]).setOpacity(0).get('rgba')]
                    ]
                },
                lineWidth: 1,
                marker: {
                    enabled: false
                },
                shadow: false,
                states: {
                    hover: {
                        lineWidth: 1
                    }
                },
                threshold: null
            }
        },
        series: _data
    });
} 
显示的结果是这样的

如何根据我在查询中收到的国家名称更改图表中的“系列1”? 我在查询中的数据的日期为“4月”(YTD),但图表显示了未来的几个月,我如何纠正这一点? 如果查询中有多个国家/地区,如何在多个图表行中同时显示这些国家/地区。
提前感谢。

您的
\u数据应该如下所示:

 [{
        name: 'USA',
        data: [[Date.UTC(2013,5,1), 7.0], [Date.UTC(2013,6,1), 5.0]]
    }, {
        name: 'Germany',
        data: [[Date.UTC(2013,5,1), 6.0], [Date.UTC(2013,6,1), 8.0]]
    }, {
        name: 'Japan',
        data: [[Date.UTC(2013,5,1), 7.0], [Date.UTC(2013,6,1), 3.0]]
  }]

因此,您需要从
\u数据

中进行一些映射,因为您只提供了一个系列,它只能转换为一行。尝试以下方法:

 $res = db_query($sql);
$dat = array(); 
while($r = db_fetch_array($res)){
    if (!isset($dat[$r['country']])) 
       $dat[$r['country']] = [];

    $dat[$r['country']][] = array($r['date'], $r['items'], $r['country']);
}

// Armar
$start_date = '';
if(count($dat)>0){
    $s = split(' ',$dat[0][0]);
    $ss = split('-',$s[0]);
}
// Cada objeto en $dats es una grafica
$dats = [];
foreach ($dat as $country => $values) {
$dats[] = array('type'=>'line',
            'name'=>$q['title'],
            'pointInterval'=>24 * 3600 * 1000,
            'pointStart'=>mktime(0,0,0,$ss[1],$ss[2],$ss[0])*1000,
            'data'=>$values) ;
}
//echo "$sql";
echo json_encode($dats,JSON_NUMERIC_CHECK);

如果到目前为止,下面的答案没有解决您的问题,那么请提供
\u data
-您的查询返回到JS的内容是什么?