图表消除所选颜色

Flot chart eliminate selected colour

我有一个使用 Flot 的堆叠面积图,效果很好。它的填充颜色当前是自动生成的。

我的问题是,我是否可以消除选定的颜色。意思是,我不希望图表使用绿色、红色和橙色作为填充颜色。

The API does not provide a way to exclude some color if it's auto-generated

我认为您可以轻松地编辑 jquery.colorhelpers.js 文件和 comment/remove 您不想要的 auto-colors

例如(未测试)

var lookupColors = {
        aqua:[0,255,255],
        azure:[240,255,255],
        beige:[245,245,220],
        black:[0,0,0],
        // blue:[0,0,255], // --> no blue
        brown:[165,42,42],
        cyan:[0,255,255],
        ...
    };

编辑:
如果您 不是 手动包含 jquery.colorhelpers.js 文件,请注意作者在第 8 行的 jquery.flot.js 文件中的评论:

8: // first an inline dependency, jquery.colorhelpers.js, we inline it here
9: // for convenience

内联代码在第 32 行:

32: (function($){$.color={};$.color.make=...

编辑 2:

Important Clarification

看了一点jquery.flot.js文件中的代码和作者的注释后,我意识到上面的建议是完全错误的... lookupColors 变量用于将 given 颜色名称与对应的 RGB 值匹配...
与图表自动生成的颜色无关。

现在......在同一阅读中,我发现了这个color theme声明jquery.flot.js第516行

516: // the color theme used for graphs
517: colors: ["#edc240", "#afd8f8", "#cb4b4b", "#4da74d", "#9440ed"],

你猜怎么着......如果你修改它......会改变图表,所以我认为这将是你最好的方法。

示例:

colors: [
    // "#edc240", // --> this removes/disabled the dark-yellow
    "#afd8f8",
    "#cb4b4b",
    "#4da74d",
    "#9440ed"
],

所以现在,您不仅可以 exclude 一些颜色,还可以创建自己的 theme
不错 ;)

jsFiddle 示例:http://jsfiddle.net/gmolop/9u8tsfum/