Highcharts选项不起作用

时间:2014-07-15 14:47:07

标签: highcharts

所以,我有这个代码,当单元格值是NaN(非数字)时,它显示的是黑色,而不是这个,以及带有所有小数的工具提示。我错过了什么?

plotOptions: {
  heatmap: {
        nullColor: '#3bd268',
        tooltip: {
          valueDecimals: 2,
        },
  },
}

http://jsfiddle.net/548DQ/

1 个答案:

答案 0 :(得分:1)

您可以将工具提示向下返回2个小数点,如下所示:

tooltip: {
            formatter: function () {
                return '<b>' + this.series.xAxis.categories[this.point.x] + '</b> sold <br><b>' +
                    this.point.value.toFixed(2) + '</b> items on <br><b>' + this.series.yAxis.categories[this.point.y] + '</b>';
            }
        }

至于你的数据,我可能会首先将数据分配给变量,然后迭代它,检测它是否是string。然后,您可以为其分配null以使其正常工作。 如果您愿意,也可以在这种情况下修复小数。

myData = [
        [0, 0, 10.873453],
        [0, 1, "aa"],
        [0, 2, 8],
        [0, 3, 24],
        [0, 4, 67],
        [1, 0, 92],
        [1, 1, 58] .....
        ................

for (var key in myData) {
        if (myData.hasOwnProperty(key)) {
            if(typeof (myData[key][2]) == 'string')
                myData[key][2] = null;
        }
    }

......

series: [{
            name: 'Sales per employee',
            borderWidth: 1,
            data: myData, // <-- Add myData here
            dataLabels: {
                enabled: true,
                color: 'black',
                style: {
                    textShadow: 'none',
                    HcTextStroke: null
                }
            }
        }]

演示:http://jsfiddle.net/robschmuecker/548DQ/1/

相关问题