我已经在这几个小时了,我不知道出了什么问题。它显示正确的图表,但我无法将鼠标悬停在任何点上。我已经阅读了我的 var_dump() 并且我的所有记录都井井有条。我是否在某些时候错误地转换了日期?
我的图表是什么样的(这是正确的):http ://screencloud.net/v/qrSS
我得到的错误:“Highcharts 错误 #15:www.highcharts.com/errors/15”
Highcharts 期望数据被排序
当您尝试创建数据未按 X 升序排序的线系列或股票图表时,会发生这种情况。出于性能原因,Highcharts 不对数据进行排序,而是要求实现者对数据进行预排序。
我的控制台:http ://screencloud.net/v/qWHO
我的highcharts代码
$.post('/card/read_graph_json', inputs, function(data) {
json = jQuery.parseJSON(data);
chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
type: 'spline'
},
global: {
useUTC: false
},
plotOptions: {
series: {
animation: false
}
},
title: {
text: '{{ $card->name }}'
},
subtitle: {
text: null
},
xAxis: {
type: 'datetime',
dateTimeLabelFormats: { // don't display the dummy year
month: '%b',
year: '%b'
}
},
yAxis: {
title: {
text: null
},
},
tooltip: {
formatter: function() {
var monthNames = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ],
date = new Date(this.x);
return '<strong>'+ this.series.name +'</strong><br/>'+ monthNames[date.getMonth()] + '. ' + date.getDay() + ', ' + date.getFullYear() +': '+ this.y;
}
},
series: [json]
});
});
我创建 JSON 的 php
public function contact_records($contact_id, $number_past_entries = 6, $reverse = false)
{
// Pull 15 records from db and order them by date created "Y-m-d H:i:s"
return $this->has_many('Record')
->where_deleted(0)
->where_contact_id($contact_id)
->order_by('created_at', 'desc')
->take($number_past_entries)
->get();
}
public function post_read_graph_json()
{
$contact_id = Input::get('contact_id');
$tracker = Tracker::find(Input::get('tracker_id'));
$card = Card::find(Input::get('card_id'));
$serie = array();
if ($tracker != null && $card != null) {
Cookie::forever("default_graph_tracker_id", $tracker->id);
$data = array();
// This is where my records come from
$records = $card->contact_records($contact_id, 15);
// Create the serie
foreach ($records as $record) {
$data[] = array(
strtotime($record->created_at) * 1000,
floatval($record->read_tracker_value($tracker->id)->value)
);
}
$serie = array(
'name' => $tracker->name,
'data' => $data
);
}
return json_encode($serie);
}