【问题标题】:How to change colors of cells in Google visualization graph table如何更改谷歌可视化图表中单元格的颜色
【发布时间】:2012-11-08 18:06:23
【问题描述】:

我正在 Google 图表中构建一个表格。我想根据单元格的数值更改单元格的颜色。我假设我将执行类似遍历所有单元格并在此处调用文档中指定的 colorFormat 对象:https://developers.google.com/chart/interactive/docs/reference#colorformatter

问题是没有具体如何实现此方法的示例。

有谁知道一个例子或如何实现 colorFormat 来改变单元格的颜色?

【问题讨论】:

    标签: javascript google-visualization


    【解决方案1】:

    https://developers.google.com/chart/interactive/docs/reference#colorformatter - 你向下滚动了吗?

    var formatter = new google.visualization.ColorFormat();
    formatter.addRange(-20000, 0, 'white', 'orange');
    formatter.addRange(20000, null, 'red', '#33ff33');
    formatter.format(data, 1); // Apply formatter to second column
    

    【讨论】:

    • 是否可以为空单元格定义颜色?
    • 是的,如果您查看 addRange 它指出:from - [String, Number, Date, DateTime, or TimeOfDay] 范围的下边界(包括),或 null .如果为 null,它将匹配 -∞。字符串边界按字母顺序与字符串值进行比较。,与 to 相同。所以你只有 from 和 to 为 null
    猜你喜欢
    • 2021-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-04
    • 2011-04-27
    相关资源
    最近更新 更多