Google图表日期格式
出于某种原因,使用模式的日期格式化程序在我的应用程序中完全不起作用。我想到的一件事是,它不允许格式化x轴。这里有一个片段:
For some reason the date formatter using a pattern isn't working at all in my application. One thing that has crossed my mind is that it doesn't allow formatting for the x axis. Here's a snippet:
var dataTable = new google.visualization.DataTable();
dataTable.addColumn('date', 'YearMonth');
dataTable.addColumn('number', 'Beds');
dataTable.addColumn('number', 'Rooms');
var monthYearFormatter = new google.visualization.DateFormat({ pattern: "MMM yyyy" });
monthYearFormatter.format(dataTable, 0);
在循环的其他地方,我执行以下操作:
So elsewhere in a loop I do the following:
dataTable.addRow(d, currentRow.Beds, currentRow.Rooms]);
其中d是有效日期。它完全没有格式化,但是当我完成所有这些工作时,它只显示默认格式。
Where "d" is a valid date. It isn't formatted at all though, however when I do all of this, it just displays the default format.
以前有人做过这个吗?
为了格式化x轴上的值,您必须使用格式
属性在选项中:
In order to format the values on the x-axis, you must use the format
attribute in the options:
hAxis: { format: 'MMM yyyy' }
行:
The line:
monthYearFormatter.format(dataTable, 0);
格式化图表中的值,必须在数据插入 dataTable
object。
formats the values in the chart and must be written after the data inserting into the dataTable
object.