3

我有多个遵循以下示例格式的数组,我想知道如何以编程方式重组数组以用于 Highcharts(特别是 Highstock)。我希望能够比较每个数组的数据,如本演示中所示。[Date] 应该是 X 轴,[Close] 应该是给定数据点的 Y 轴。

数组示例:

Array
(
    [0] => Array
        (
            [Date] => 2013-03-06
            [Open] => 3.79
            [High] => 3.64
            [Low] => 3.48
            [Close] => 3.52
            [Volume] => 22184500
            [Adj Close] => 3.72
        )

    [1] => Array
        (
            [Date] => 2013-03-05
            [Open] => 3.63
            [High] => 3.05
            [Low] => 3.28
            [Close] => 3.54
            [Volume] => 32987900
            [Adj Close] => 3.14
        )

    [2] => Array
        (
            [Date] => 2013-03-04
            [Open] => 3.50
            [High] => 3.67
            [Low] => 3.50
            [Close] => 3.64
            [Volume] => 47933200
            [Adj Close] => 3.84
        )
)

如果您需要更多信息或有任何问题,请告诉我。

谢谢

4

2 回答 2

1

如果你做这样的事情:

   $i = 0;
    foreach($your_array as $val){
       $res[$i][]   = strtotime($val['Date']) * 1000; //sets the date as a javascript timestamp
       $res[$i][]   = (float)$val['Close']; //make sure it is formatted as a number not a string
       $i++;
    }
    json_encode($res);

您应该有 json 可以作为图表中的数据对象传递。

于 2013-03-07T18:34:28.043 回答
0

我不确定你到底在寻找什么,

试试这个 :

$res              = array();
foreach($your_array as $key=>$val){
   $res[$key]['Date']   = $val['Date'];
   $res[$key]['Close']  = $val['Close'];
}

echo "<pre>";
print_r($res);
于 2013-03-07T13:21:48.557 回答