了解 Google DataTable 前缀

发布于 2024-11-27 15:43:25 字数 423 浏览 5 评论 0原文

Google DataTable 将此字符串作为架构和数据值:

{ 
cols: [{id: 'task',  label: 'Task',          type: 'string'}, 
      {id: 'hours', label: 'Hours per Day', type: 'number'}], 
rows: [{c:[{v: 'Work'},     {v: 11}]}, 
      {c:[{v: 'Eat'},      {v: 2}]}, 
      {c:[{v: 'Commute'},  {v: 2}]}, 
      {c:[{v: 'Watch TV'}, {v:2}]}, 
      {c:[{v: 'Sleep'},    {v:7, f:'7.000'}]} 
     ] 
} 

什么是 v、f、c?

Google DataTable has this string as schema and data values:

{ 
cols: [{id: 'task',  label: 'Task',          type: 'string'}, 
      {id: 'hours', label: 'Hours per Day', type: 'number'}], 
rows: [{c:[{v: 'Work'},     {v: 11}]}, 
      {c:[{v: 'Eat'},      {v: 2}]}, 
      {c:[{v: 'Commute'},  {v: 2}]}, 
      {c:[{v: 'Watch TV'}, {v:2}]}, 
      {c:[{v: 'Sleep'},    {v:7, f:'7.000'}]} 
     ] 
} 

What is v, f, c?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

屋檐 2024-12-04 15:43:25

文档,看起来,您可以在其中找到示例中的结构描述链接:

opt_data
[可选] 用于初始化表的数据。这可以是通过在填充表上调用 DataTable.toJSON() 返回的 JSON,也可以是包含用于初始化表的数据的 JavaScript 对象。 此处描述了 JavaScript 文字对象的结构。如果未提供此参数,将返回一个新的空数据表。


这导致:

属性

rows 属性保存一个行对象数组。
每个行对象都有一个名为 c 的必需属性,它是该行中的一组单元格。它还具有一个可选的 p 属性,该属性定义要分配给整行的任意自定义值的映射。如果您的可视化支持任何行级属性,它将对其进行描述;否则,该属性将被忽略。

单元格对象

表中的每个单元格由具有以下属性的对象描述:

  • v [可选] 单元格值。数据类型应与列数据类型匹配。如果为 null,则整个对象应该为空,并且既没有 v 也没有 f 属性。
  • f [可选] v 值的字符串版本,经过格式化以供显示。这些值应该匹配,因此如果您为 v 指定 Date(2008, 0, 1),则应为此属性指定“January 1, 2008”或类似的字符串。该值不会根据 v 值进行检查。可视化不会使用该值进行计算,仅作为显示的标签。如果省略,将使用 v 的字符串版本。
  • p [可选] 一个对象,它是应用于单元格的自定义值的映射。这些值可以是任何 JavaScript 类型。如果您的可视化支持任何单元格级属性,它将描述它们;否则,该属性将被忽略。 示例: p:{style: 'border: 1px Solid green;'}.

The documentation, where, as it seems, you got the example from, links to a description of the structure:

opt_data
[Optional] Data used to initialize the table. This can either be the JSON returned by calling DataTable.toJSON() on a populated table, or a JavaScript object containing data used to initialize the table. The structure of the JavaScript literal object is described here. If this parameter is not supplied, a new, empty data table will be returned.

Which leads to:

rows Property

The rows property holds an array of row objects.
Each row object has one required property called c, which is an array of cells in that row. It also has an optional p property that defines a map of arbitrary custom values to assign to the whole row. If your visualization supports any row-level properties it will describe them; otherwise, this property will be ignored.

Cell Objects

Each cell in the table is described by an object with the following properties:

  • v [Optional] The cell value. The data type should match the column data type. If null, the whole object should be empty and have neither v nor f properties.
  • f [Optional] A string version of the v value, formatted for display. The values should match, so if you specify Date(2008, 0, 1) for v, you should specify "January 1, 2008" or some such string for this property. This value is not checked against the v value. The visualization will not use this value for calculation, only as a label for display. If omitted, a string version of v will be used.
  • p [Optional] An object that is a map of custom values applied to the cell. These values can be of any JavaScript type. If your visualization supports any cell-level properties, it will describe them; otherwise, this property will be ignored. Example: p:{style: 'border: 1px solid green;'}.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文