如何从Highcharts xrange图表

时间:2018-05-25 17:14:44

标签: javascript highcharts

想要使用X范围图表,其中显示的数字和百分比已完全删除。

从文档中,我认为将undefined作为参数放在partialFill中会完全删除它。但它似乎只会导致Bar显示零百分比。

          partialFill: 0.25

https://jsfiddle.net/gh/get/library/pure/highcharts/highcharts/tree/master/samples/highcharts/demo/x-range/

以上是他们的xrange图表的HighCharts演示版本的链接。以下是代码:

Highcharts.chart('container', {
   chart: {
         type: 'xrange'
   },
   title: {
         text: 'Highcharts X-range'
   },
   xAxis: {
         type: 'datetime'
   },
   yAxis: {
          title: {
          text: ''
    },
   categories: ['Prototyping', 'Development', 'Testing'],
   reversed: true
},
series: [{
    name: 'Project 1',
    // pointPadding: 0,
    // groupPadding: 0,
    borderColor: 'gray',
    pointWidth: 20,
    data: [{
        x: Date.UTC(2014, 10, 21),
        x2: Date.UTC(2014, 11, 2),
        y: 0,
        partialFill: 0.25
    }, {
        x: Date.UTC(2014, 11, 2),
        x2: Date.UTC(2014, 11, 5),
        y: 1
    }, {
        x: Date.UTC(2014, 11, 8),
        x2: Date.UTC(2014, 11, 9),
        y: 2
    }, {
        x: Date.UTC(2014, 11, 9),
        x2: Date.UTC(2014, 11, 19),
        y: 1
    }, {
        x: Date.UTC(2014, 11, 10),
        x2: Date.UTC(2014, 11, 23),
        y: 2
    }],
    dataLabels: {
        enabled: true
    }
  }]
});

1 个答案:

答案 0 :(得分:0)

名叫丹尼尔的人在Highcharts论坛上回答了这个问题,我将在下面给出答案:

嗨KodaroKid,

如果我理解正确,你的意思是你不想在图表上显示没有partialFill的点数据标签,对吗?如果是,为了达到预期的效果,需要使用dataLabels.formatter函数,并检查partialFill是否在特定点定义,然后格式化并显示其值。否则返回空字符串。请看下面的代码:

实例:https://jsfiddle.net/fmca01cz/

     dataLabels: {
        enabled: true,
        formatter: function() {
          var percents = this.point.partialFill
          return percents ? percents * 100 + '%' : ''
      }

API参考:https://api.highcharts.com/highcharts/series.xrange.dataLabels.formatter

祝你好运!