gpt4 book ai didi

javascript - 谷歌可视化 API : how to apply a pattern on addColumn

转载 作者:行者123 更新时间:2023-11-30 16:01:27 24 4
gpt4 key购买 nike

当我尝试在 addColumn 中指定一个模式时,它没有显示。我做错了什么?

data.addColumn({
type: 'date',
label: 'Date',
pattern: "EE dd MMM yyyy"
});
data.addRow([new Date(2016, 02, 05)])

显示值是 Mar 5, 2016 这是默认格式,而我预计 Sat 05 Mar 2016addColumn({pattern: "EE dd MMM yyyy"})

参见 https://jsfiddle.net/qpq3kvhr/3 number 也存在同样的问题。

我在谷歌上搜索了 addColumn(pattern) 的工作示例,但没有找到。

最佳答案

addColumn documententation状态:

addColumn(type, opt_label, opt_id) OR
addColumn(description_object)
Second signature has a single object parameter with the following members:
...

  • pattern - [Optional, string] A number (or date) format string specifying how to display the column value.

但这是错误的,或者至少是令人困惑的。在 Constructor's JavaScript Literal data parameter 的文档中有不同的解释

cols Property

cols is an array of objects describing the ID and type of each column. Each property is an object with the following properties (case-sensitive):
...

  • pattern [Optional] String pattern that was used by a data source to format numeric, date, or time column values. This is for reference only; you probably won't need to read the pattern, and it isn't required to exist. The Google Visualization client does not use this value (it reads the cell's formatted value). If the DataTable has come from a data source in response to a query with a format clause, the pattern you specified in that clause will probably be returned in this value.

结论:您不能在 dataTable 或 addColumn 构造函数中指定自动应用的格式模式。相反,应用 formatter之后的专栏。

var formatter = new google.visualization.DateFormat({pattern: "EE dd MMM yyyy"});
formatter.format(data, 0);

fiddle https://jsfiddle.net/qpq3kvhr/6/

关于javascript - 谷歌可视化 API : how to apply a pattern on addColumn,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37673076/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com