1
您好我正在嘗試使用谷歌圖表來繪製圖表,它將顯示sub_task
和estimated_duration
的start_day
,我正在使用數據庫來檢索我的數據,並將數據轉換爲JSON對象繪製到圖形但是我收到以下錯誤:谷歌圖表類型不匹配繪製時間值到圖表上
Uncaught Error: Type mismatch. Value
01:00:00,02:20:00,00:20:00,02:20:00,01:23:00,02:20:00,02:20:00,01:00:00,
01:23:00,01:00:00 does not match type datetime in column index 1
format+en_GB,default+en_GB,ui+en_GB,corechart+en_GB.I.js:169
這是怎麼了獲取繪製我的數據:
@extends("layouts.master")
@section("content")
<div id="visualization" style="width: auto; height: 400px;"></div>
<script type="text/javascript" src="//www.google.com/jsapi"></script>
<script type="text/javascript">
google.load('visualization', '1', {packages: ['corechart']});
</script>
<script>
function drawVisualization() {
// Create and populate the data table.
var dataTable= new google.visualization.DataTable();
dataTable.addColumn('datetime', 'Year');
dataTable.addColumn('datetime', 'estimated_duration');
dataTable.addRows([
[new Date({{ json_encode($start_day) }}),{{ json_encode($estimated_duration) }} ]]);
new google.visualization.DateFormat({pattern: 'yyyy/MM/dd HH:mm:ss'}).format(dataTable, 0);
// Create and draw the visualization.
var chart = new google.visualization.LineChart(document.getElementById('visualization'));
chart.draw(dataTable, {curveType: "function"});
}
google.setOnLoadCallback(drawVisualization);
</script>
@stop
在我的數據庫中的數據值都是這種格式:
`start_day` = `2013-02-10`
`duration` = `01:00:00`
在laravel我正在檢索我的數據在倉庫像這樣:
public function subtaskDurationReport() {
return \Auth::user()->subtasks()->limit(10)->get();
}
然後在我的控制器I值傳遞給視圖
public function reports()
{
$subtask = $this->subtask->subtaskDurationReport();
return View::make('subtasks.reports')
->with([
'start_day' => $subtask->lists('start_day'),
'estimated_duration' => $subtask->lists('estimated_duration')
]);
}
有東西我做錯了?我需要轉換start_day
或estimated_duration
格式嗎?任何建議和意見都很重要。
01:00:00不是日期時間。日期時間應該只有1列,start_date和持續時間 – juvian 2014-09-22 17:32:47
@juvian當我更改爲持續時間我得到此錯誤:未捕獲錯誤:無效的類型,持續時間,爲列 – 001221 2014-09-22 18:14:21
我的意思是你只需要1列類型dateTime,與日期和時間 – juvian 2014-09-22 18:33:09