highcharts定制datalabels复制(highcharts custom datalab

2019-09-28 02:34发布

谁能告诉我,为什么在某些情况下出现了两次我的图表上自定义datalabels? 请注意,这是不相关的在出口业务的错误,但我设置textshadow以防万一“无”。 它似乎并不一致。 提前致谢。

该的jsfiddle是在这里: https://jsfiddle.net/zh3hvya3/

<html>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs jquery/1.8.2/jquery.min.js"></script>
<style type="text/css">
#container {
    height: 400px; 
    min-width: 310px; 
    max-width: 800px;
    margin: 0 auto;
}
</style>

<script type="text/javascript">          

$(function () {
  window.chart1 = new Highcharts.Chart({
     chart: {
        renderTo: 'container',
        type: 'columnrange',
        inverted: true
     },
     title: {
        text: 'Tractor Utilization Chart'
     },
     xAxis: {
        title: {
            text: 'Vehicle'
        },
        categories: ['970106', '970108', '970110', '970111']
     },
     yAxis: {
        type: 'datetime',
        gridLineWidth: 1,
        gridLineColor: '#888888',
        min: 1463893200000,
        max: 1464498000000,
        tickInterval: 6 * 3600 * 1000,
        title: {
            text: 'Day and Time'
        }
     },
     legend: {
        enabled: true,
        labelFormatter: function() {
            return 'ABC';
        }
     },
     plotOptions: {
        columnrange: {
            grouping: false
        }
     },
     series: [{
        data: [{
            color: 'cyan',
            dataLabels: {
                enabled: true,
                align: 'left',
                style: {
                    textShadow: 'none'
                },
                formatter: function() {
                    return '20614523';
                }
            },
            x: 0,
            low: 1464057000000,
            high: 1464114900000
        }, {
            color: 'cyan',
            dataLabels: {
                enabled: true,
                align: 'left',
                style: {
                    textShadow: 'none'
                },
                formatter: function() {
                    return '20614531';
                }
            },
            x: 1,
            low: 1464060600000,
            high: 1464120660000
        }, {
            color: 'cyan',
            dataLabels: {
                enabled: true,
                align: 'left',
                style: {
                    textShadow: 'none'
                },
                formatter: function() {
                    return '20614601';
                }
            },
            x: 2,
            low: 1464048000000,
            high: 1464078538000
        }, {
            color: 'cyan',
            dataLabels: {
                enabled: true,
                align: 'left',
                style: {
                    textShadow: 'none'
                },
                formatter: function() {
                    return '20614504';
                }
            },
            x: 3,
            low: 1463967000000,
            high: 1464011852000
        }],
     }, {
        data: [{
            color: 'cyan',
            dataLabels: {
                enabled: true,
                align: 'left',
                style: {
                    textShadow: 'none'
                },
                formatter: function() {
                    return '20614502';
                }
            },
            x: 0,
            low: 1463947200000,
            high: 1463994392000
        }]
     }]
   });
}); 

</script>
</head>

<body>    
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/highcharts-more.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>    
<div id="container" style="height: 400px"></div>
</body>
</html>

Answer 1:

一为低,一个用于高 - 在我的评论,范围系列显示两个数据标签说明。

在你的情况,因为有些数据点的距离很近,图表隐藏其中的一个,以避免重叠。 因此,只有较长范围显示两个数据标签。

参考:

  • http://api.highcharts.com/highcharts#plotOptions.columnrange.dataLabels.allowOverlap

只显示一个数据点,你可以做格式化函数内部检查,看是否point.y值等于point.high值。

例:

formatter: function() {
  if (this.y == this.point.high) {
    return this.point.val;
  }
}

小提琴:

  • https://jsfiddle.net/jlbriggs/4aoxt7p0/


文章来源: highcharts custom datalabels duplicating
标签: highcharts