我有一组代表不同时间序列的数组:
Array
(
[0] =>
[2014-01-08] => 1408
[2014-01-09] => 1357
[2014-01-10] => 1272
[2014-01-11] => 1625
[2014-01-12] => 1516
[2014-01-13] => 2002
[2014-01-14] => 2301
)
Array
(
[0] =>
[2014-01-21] => 32
[2014-01-22] => 234
[2014-01-23] => 195
[2014-01-24] => 176
[2014-01-25] => 231
...
我想在HighCharts linechart
中显示此数据。
我知道这可以通过文档来完成:http://jsfiddle.net/gh/get/jquery/1.9.1/highslide-software/highcharts.com/tree/master/samples/highcharts/demo/spline-irregular-time/。
如果我忽略期间不相同,我可以用Highroller创建一个情节:
foreach(array_keys($arrays) as $campaign_name) {
$data = array_values($arrays[$campaign_name]);
$series[$campaign_name] = new HighRollerSeriesData();
$series[$campaign_name]->addName($campaign_name)->addData($data);
}
但此图表中的所有行都以x = 0开始。
然后我尝试创建一个类似于上面的jsfiddle
的syntex,但情节不呈现:
foreach(array_keys($arrays) as $campaign_name) {
$data = array_values($arrays[$campaign_name]);
$dates = array_keys($arrays[$campaign_name]);
$data = array_combine($dates, $data);
$series[$campaign_name] = new HighRollerSeriesData();
$series[$campaign_name]->addName($campaign_name)->addData($data);
}
答案 0 :(得分:0)
您可以定义数据,然后将其修改为timestamp
演示:http://jsfiddle.net/robschmuecker/NHnkQ/
myDataSeries1 = [
["2014-01-08", 1408],
["2014-01-09", 1357],
["2014-01-10", 1272],
["2014-01-11", 1625],
["2014-01-12", 1516],
["2014-01-13", 2002],
["2014-01-14", 2301]
];
myDataSeries2 = [
["2014-01-21", 32],
["2014-01-22", 234],
["2014-01-23", 195],
["2014-01-24", 176],
["2014-01-25", 231]
];
$.each(myDataSeries1, function (index, item) {
item[0] = new Date(item[0]).getTime();
});
$.each(myDataSeries2, function (index, item) {
item[0] = new Date(item[0]).getTime();
});
... /// Further down
series: [{
name: 'MyData1',
data: myDataSeries1
}, {
name: 'MyData2',
data: myDataSeries2
}]