问题
So, I have got this code, and when the cell value is NaN (Not a number), it is showed with the black colour, not with this one, and the tooltip with all the decimals. What am I missing?
plotOptions: {
heatmap: {
nullColor: '#3bd268',
tooltip: {
valueDecimals: 2,
},
},
}
http://jsfiddle.net/548DQ/
回答1:
You can return the tooltip down to say 2 decimal points as such:
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>';
}
}
As for your data, I would perhaps assign the data to variable first and then iterate over it detecting if it is a string
. Then you can assign a null
to it to make it work correctly.
You could also in this instance fix the decimals if you so wished.
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
}
}
}]
Demo: http://jsfiddle.net/robschmuecker/548DQ/1/
来源:https://stackoverflow.com/questions/24761282/highcharts-options-not-working