PHP array to Highcharts


PHP array to Highcharts

如何从数组到Highcharts获取此数据?

    [0] => Array
        (
            [0] => Date
            [1] => data1
            [2] => data2
        )
    [1] => Array
        (
            [0] => 2015-03-26 02:00
            [1] =>      1,425
            [2] =>     39,294
        )
    [2] => Array
        (
            [0] => 2015-03-26 03:00
            [1] =>      1,422
            [2] =>     39,076
        )

我是PHP的新手,正在寻找一种方法来获得第一个键(日期)作为x轴,key2 (data2)作为y轴。可以通过选择数组中的所有键值,并将其传递给这个javascript的Highcharts吗?

$(function () { 
            $('#container').highcharts({
                chart: {
                    type: 'line'
                },
                title: {
                    text: 'Chart Title'
                },
                xAxis: {
                    categories: //Dates here 2015-03-26 02:00//
                },
                yAxis: {
                    title: {
                        text: 'a text here'
                    }
                },
                series: [{
                    name: 'data1',
                    data: // key1 from array 1,425 //
                }, {
                    name: 'data2',
                    data: // key2 from array 39,294 //
                }]
            });
        });
$data = array
(
    array
    (
        "Date",
        "data1",
        "data2"
    ),
    array
    (
        "2015-03-26 02:00",
        "1,425",
        "39,294"
    ),
    array
    (
        "2015-03-26 03:00",
        "1,422",
        "39,076"
    )
);
$series = array();
// Get the items of the first array
$items = $data[0];
foreach($items as $itemIndex => $value)
{
    // Skip the 'Date'
    if (!$itemIndex)
        continue;
    // We should have the actual array to add to the 'data', if not skip
    if (empty($data[$itemIndex]))
        continue;
    $series[] = array
    (
        "name" => $value,
        "data" => $data[$itemIndex]
    );
}
echo json_encode($series);