Highchart:柱形图中的绘图选项中的中心文本

时间:2016-08-10 08:28:31

标签: javascript css charts highcharts

var binary = 0b1101000; // code for 104
console.log(binary); // prints 104

我想在上面的列/中心中心显示5%,1%,0%(N = 600)

Here is the image

这是jsfiddle

2 个答案:

答案 0 :(得分:3)

添加useHTML并将元素居中。

参考Highcharts Labels and String Formatting

dataLabels: {
    enabled: true,
    useHTML: true,
    formatter: function () {
    return '<center><b>'+Math.round(this.point.y)+'%</b></center>'
      +'<br><center><b>(N='+ this.point.count + ')</b><center>';
}

如果您想要导出,请在导出时添加以下allowHTML。

exporting: {
    allowHTML: true
}

参考Highcharts exporting API

答案 1 :(得分:2)

基于Rockie Yang的代码,我发现您需要添加导出属性allowHTML并将其设为true。默认情况下它是假的,allowHTML允许您在导出的图表中保留HTML结构。

JSFiddle:http://jsfiddle.net/henrikskar/oos3bqov/

exporting: {
        enabled: true,
        allowHTML: true
    }