gpt4 book ai didi

javascript - 对象文字 DataTable 中的 Google 可视化样式 Angular 色

转载 作者:行者123 更新时间:2023-12-03 10:42:11 24 4
gpt4 key购买 nike

我正在根据 AJAX 数据创建 Google Visualizations(当前为 ColumnCharts),方法是根据以下文档返回适合传递给 DataTable 构造函数的对象文字:

https://developers.google.com/chart/interactive/docs/reference#dataparam

数据一切正常,但我不知道如何让样式 Angular 色发挥作用。我认为文档说要创建以下内容,但它没有设置颜色;我做错了什么?

{  
"cols":[
{
"id":"x",
"type":"number",
"label":"Period"
},
{
"id":"quotes",
"type":"number",
"label":"Quotes"
},
{
"id":"quotes_style",
"type":"number",
"p":{
"role":"style"
}
},
{
"id":"orders",
"type":"number",
"label":"Converted to Orders"
},
{
"id":"orders_style",
"type":"number",
"p":{
"role":"style"
}
}
],
"rows":[
{
"c":[
{
"v":0,
"f":"2/2015"
},
{
"v":4
},
{
"p":{
"style":"color:#dddddd"
}
},
{
"v":3
},
{
"p":{
"style":"color:#00d67c"
}
}
],
"p":null
}
],
"p":null
}

最佳答案

好的,已修复;首先,在 cols 中,列的 type 应该是 string;然后在 rows 中,样式列应该将 v 设置为样式字符串,而不是 p

(通过在帮助文档中的工作数组上调用 google.visualization.arrayToDataTable() 并在结果上调用 .toJSON() 找到了这一点 - 非常方便! )

最终 JSON:

{  
"cols":[
{
"id":"x",
"type":"number",
"label":"Period"
},
{
"id":"quotes",
"type":"number",
"label":"Quotes"
},
{
"id":"quotes_style",
"type":"string",
"p":{
"role":"style"
}
},
{
"id":"orders",
"type":"number",
"label":"Converted to Orders"
},
{
"id":"orders_style",
"type":"string",
"p":{
"role":"style"
}
}
],
"rows":[
{
"c":[
{
"v":0,
"f":"2/2015"
},
{
"v":4
},
{
"v":"color:#dddddd"
},
{
"v":3
},
{
"v":"color:#00d67c"
}
],
"p":null
}
],
"p":null
}

关于javascript - 对象文字 DataTable 中的 Google 可视化样式 Angular 色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28723185/

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