无效数据时的 Highcharts 热图背景色

Highcharts Heatmap background color when invalid data

当我在 Highcharts Heatmap 上呈现字符串等无效数据时,它会以黑色背景显示该字符串。以下是无效数据的示例:

data: [[0, 0, "A"], [1, 0, "B"], [2, 0, "C"], [3, 0, "D"], [4, 0, "E"]]

我可以更改此默认行为并显示另一种背景颜色而不是黑色吗?

当您使用不受支持的值时,ColorAxis.toColor 函数 returns rgb(NaN,NaN,NaN) 作为单元格的颜色。 通过为该函数编写一个相当小的包装器,您可以拦截字符串值和 return 您选择的颜色。

例如 (JSFiddle demo):

(function (H) {
    H.wrap(H.ColorAxis.prototype, 'toColor', function (proceed, value, point) {
        if(typeof value === 'string') // String value -> Return pink
            return 'rgb(255,105,180)'; 
        else // Normal value -> Proceed as usual
            return proceed.apply(this, Array.prototype.slice.call(arguments, 1));
    });
}(Highcharts));