2012-01-18 67 views
8

我有一個帶有X軸值的柱狀圖,這是一個日期。這個圖表今天早上工作,但突然中斷,並顯示「不支持值域軸的酒吧系列。」作爲錯誤消息。有問題的網站在幾周內沒有更新。帶日期軸不起作用的柱狀圖

我的數據表結構的代碼如下所示:

var data= new google.visualization.DataTable({ 
     "cols":[{"label":"Date","type":"date"},{"label":"New Users","type":"number"}], 
     "rows":[{"c":[{"v":new Date(1325656800000),"f":null},{"v":1355,"f":null}]}] 
    }); 

我可以做我的代碼怎麼解決這個問題?

+0

看起來它與日期字段有關。我有同樣的問題。 – 2012-01-18 20:00:03

+0

今天他們推出了新版本:https://groups.google.com/forum/#!topic/google-visualization-api/1A-lfiFeLvc – 2012-01-18 20:26:53

回答

3

問題在於日期字段。我已經將日期字段轉換爲一個字符串,現在我正在使用一個字符串。如果您使用的格式化,您可以將其提供給數據表之前格式化值:

formatter.formatValue(date) 

我猜這是一個錯誤;我會嘗試提交錯誤報告。

+1

http://code.google.com/p/google- visual-api-issues/issues/detail?id = 795&thanks = 795&ts = 1326917431 – 2012-01-18 20:26:12

+0

看起來這是一個'功能' – JeffreyABecker 2012-01-18 21:32:30

+2

在創建圖表時將傳入的選項添加爲「strictFirstColumnType:false」被列爲「臨時修復「這個問題。看到這裏:http://code.google.com/apis/chart/interactive/docs/customizing_axes.html#Help – 2012-01-18 21:42:49

10

這不是一個錯誤。 Google可視化API已更改。

http://code.google.com/apis/chart/interactive/docs/customizing_axes.html#Help他們發佈了一些解決方案來解決這個問題。使用選項:

strictFirstColumnType: false 

只能用作臨時解決方案。谷歌說:

但請記住,此選項僅適用於有限的時間,並將在不久的將來被刪除。

推薦的解決方案是,您將x軸上的日期字段更改爲字符串。在將值添加到DateTable對象之前,我已經通過使用格式化程序來實現此目的。

var formatterMoney = new google.visualization.NumberFormat({suffix: ' zł', decimalSymbol: ',', groupingSymbol: ' '}); 
var formatterDate = new google.visualization.DateFormat({pattern: 'dd.MM.yyyy'}); 

var data = new google.visualization.DataTable(); 

data.addColumn('string', 'order date'); //used to be date field here 
data.addColumn('number', 'total amount'); 
data.addRow([formatterDate.formatValue(new Date('2011-12-20')),971793.93]); //used to be Date object, now is Date formated as String 
data.addRow([formatterDate.formatValue(new Date('2011-11-30')),1.0]); 
data.addRow([formatterDate.formatValue(new Date('2011-11-17')),1.0]); 
data.addRow([formatterDate.formatValue(new Date('2011-10-27')),1.72]); 
data.addRow([formatterDate.formatValue(new Date('2011-10-26')),10.27]); 

var chart = new google.visualization.ColumnChart(document.getElementById('chart_div')); 
formatterMoney.format(data, 1); 
chart.draw(data, {width: window.width, height: 400, hAxis: {direction: -1}}); 
+1

+1爲此答案!感謝代碼示例! – 2012-05-10 21:58:55