自定义Highcharts xaxis标签

时间:2016-11-18 07:46:21

标签: javascript jquery highcharts label

我可以使用Highcharts创建这样的图表吗? Expect result

其实我自己做了一些与Highcharts类似的事情,但是当我自定义Highcharts xaxis标签时我遇到了问题,是否有任何人可以帮助我?

$(function () {
    Highcharts.chart('container', {
        chart: {
            type: 'bar'
        },
        title: {
            text: null
        },
        xAxis: {
            categories: ['VISIONLINK', 'PRODUCT LINK WEB', 'CAT DAILY', 'NOT CONNECTED'],
            title: {
                text: null
            },
   					lineColor: 'transparent',
            minorTickLength: 0,
   					tickLength: 0,
        		labels: {
            useHTML: true,
            formatter: function() {
                return '<strong class="hc-label">' + this.value + '</strong>';
            }
        }
        },
        yAxis: {
            min: 0,
            title: {
                text: null,
                align: 'high'
            },
            labels: {
                enabled: false,
            },

            minorTickLength: 0,
   					tickLength: 0,
            gridLineColor: 'transparent',
           
            
        },
        tooltip: {
            enabled: false
        },
        plotOptions: {
            bar: {
                dataLabels: {
                    enabled: true,
                    align: 'right',
                    color:'black',
                    x: 30
                }
            },
            series: {
                stacking: 'normal',
               	pointWidth: 50,
                pointPadding: 0,

            }
        },
        legend: {
            enabled:false
        },
        credits: {
            enabled: false
        },
        series: [{
            
            name: 'VISIONLINK',
            data: [20,null,null,null]
        }, {
            
            name: 'PRODUCT LINK WEB',
            data: [null,40,null,null]
        }, {
            
            name: 'CAT DAILY',
            data: [null,null,200,null]
        },
         {
            name: 'NOT CONNECTED',
            data: [null,null,null,40]
        }]
    });
});
.hc-label {
  background-color: #efefef;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>

<div id="container" style="min-width: 310px; max-width: 800px; height: 400px; margin: 0 auto"></div>

查看我的DEMO

1 个答案:

答案 0 :(得分:0)

这是可以实现的,但我认为使用第二个系列模拟标签可能比直接自定义轴标签更容易。

模仿标签的系列配置如下:

, {
  color: '#efefef',
  enableMouseTracking: false,
  showInLegend: false,
  data: [
    ['VISIONLINK', 50],
    ['PRODUCT LINK WEB', 50],
    ['CAT DAILY', 50],
    ['NOT CONNECTED', 50]
  ],
  dataLabels: {
    format: '{key}'
  }
}

示例:http://jsfiddle.net/g3asmfj7/3/