Highstock:如何格式化xAxis十字线标签?

时间:2020-11-06 23:58:35

标签: highcharts format cross-hair-label x-axis

我尝试格式化xAxis十字线标签,但是默认标签总是与格式化标签重叠。在示例中,我怎么只有红色标签?换句话说,我们如何使用HighStock格式化xAxis十字准线标签(这种行为似乎与HighCharts不同)。

第二个问题:为什么xAxis标签显示0、1、2、3而不显示serie中指定的1、2、3、4?

Highcharts.stockChart('container', {
  xAxis: {
    title: {
      text: 'Price'
    },
    ordinal: false,
     labels: {   formatter: function () {return this.value;}},
    crosshair: {
      width: 0.5,
      color: 'black',
      label: {
        backgroundColor:  'rgb(255,0,0)',
        formatter: function (value) {
          return 'this is a long label: '+value;
        },
        enabled: true,
        padding: 8
      }
    }
  },

  yAxis: {
      labels: {
            formatter: function () {
                return this.value + ' units';
            }
        }
    },

    rangeSelector: {
        enabled: false
    },
    navigator: {
        enabled: false
    },

   series: [{
        type: 'areaspline',
        data: [['1',1],['2',3],['3',1],['4',4]]
    }]
});

JSFiddle example

1 个答案:

答案 0 :(得分:0)

第二个标签是工具提示标题,要禁用它,请设置:

    tooltip: {
        headerFormat: ''
    }

关于第二个问题:数据格式中的字符串被视为点名称,因此:

data: [
  ['1', 1],
  ...
]

设置:

data: [
  [1, 1],
  ...
]

实时演示: https://jsfiddle.net/BlackLabel/1g4m2ka8/

API参考: https://api.highcharts.com/highstock/tooltip.headerFormat

相关问题