我在highchart中使用柱形图我想以日期格式显示x轴,我从我的帐户的谷歌分析数据中获取。我想查看x轴上的日期,而不是我的格式想要格式化的方式。它像这样“20151001”,我希望它像这样“01-10-2015”我的数据来自谷歌分析帐户,所以我不能使用 highchart 数据这是我的代码
我从中获取日期的php代码
$matrics='ga:sessions,ga:pageviews';
$results_top_pages = $analytics->data_ga->get(
'ga:109200082',
date('Y-m-d',strtotime('-6 days')),
date('Y-m-d',strtotime('now')),
$matrics,
array(
'dimensions' => 'ga:date',
// 'sort' => '-ga:pageviews', for acsending and decending page view sorting
'filters'=>'ga:browser%3D~%5E'.$browser.'',
'max-results' => 50
));
if(is_array($results_top_pages->getRows())){
echo '<ol>';
foreach($results_top_pages->getRows() as $top_page){
echo '<li>';
echo $top_page[0];
echo ' - '.$top_page[1].' ';
echo ' - '.$top_page[2].' ';
$data[]=$top_page[2];
$date[]=$top_page[0];
echo '</li>';
}
echo '</ol>';
}
通过 $date 的 var_dump 我得到这种格式的日期:
array(7) {
[0]=>
string(8) "20150930"
[1]=>
string(8) "20151001"
[2]=>
string(8) "20151002"
[3]=>
string(8) "20151003"
[4]=>
string(8) "20151004"
[5]=>
string(8) "20151005"
[6]=>
string(8) "20151006"
}
从这里编辑的代码
:: This is js code for highchart:
$data[]=$top_page[2];
$date[]=date('d-m-y',strtotime($top_page[0]));
// echo '</li>';
}
echo '</ol>';
}
var_dump($date[0]);
$datefirst= date('U', strtotime($date[0])) * 1000;
?>
<script>
$(function () {
$('#container').highcharts({
//alert("call");
chart: {
type: 'column'
},
title: {
text: 'Weekly Traffic'
},
subtitle: {
//text: 'Source: WorldClimate.com'
},
xAxis: {
categories: [<?php echo join($date,','); ?>],
max:6
},
yAxis: {
title: {
text: 'Views'
}
},
plotOptions: {
line: {
dataLabels: {
enabled: true,
connectNulls: false
},
enableMouseTracking: false
}
},
series: [{
pointStart: '<?php echo $datefirst; ?>',
pointInterval: 86400000, //one day
pointRange: 86400000, //one day
name: '<?php echo $browser; ?>',
data: [<?php echo join($data, ',') ?>],
//pointStart: Date.UTC(2015, 0, 1),
// pointInterval: 24 * 3600 * 1000
},
]
});
});
</script>
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>