Google图表日期格式 [英] Google Charts Date Formats

查看:83
本文介绍了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.

这篇关于Google图表日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆