2012-01-18 69 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