具有不同时间间隔的系列的工具提示

时间:2021-07-22 10:13:36

标签: javascript highcharts

我有以下问题。 我向 highchart 提供数据。碰巧我提供的每一系列数据都有15分钟的时间间隔,除了1分钟的时间间隔。 工具提示(在图表上悬停鼠标时)以这样的方式出现: 每隔一分钟就有一个系列的工具提示,间隔为 1 分钟,每 15 分钟有一个所有系列的工具提示。

我希望它们每 15 分钟出现一次。

这是我的高图配置:

{
      chart: {
        height: 500,
        spacingRight: 70
      },
      title: {
        text: ''
      },
      legend: {
        enabled: true
      },
      xAxis: {
        type: 'datetime',
        
      },
      rangeSelector: {
        selected: 5,
        inputEnabled: false,
        buttonTheme: {
          visibility: 'hidden'
        },
        labelStyle: {
          visibility: 'hidden'
        }
      },
      navigator: {
        enabled: false
      },
      credits: {
        enabled: false
      },
      scrollbar: {
        enabled: false
      },
      yAxis: [
        {
          title: {
            text: ''
          },
          labels: {
            x: 50,
            format: '{value} kW'
          },
          showLastLabel: true
        },
        {
          title: {
            text: ''
          },
          labels: {
            format: '{value} ˚C'
          },
          opposite: false,
          showLastLabel: true
        }
      ],
      tooltip: {
        shared: true,
        split: false
      },
      plotOptions: {
        column: {
          stacking: 'normal',
          dataGrouping: {
            enabled: false
          },
          dataLabels: {
            enabled: false
          }
        },
        area: {
          stacking: 'normal',
          dataGrouping: {
            enabled: false
          },
          dataLabels: {
            enabled: false
          }
        }
      },
      series: this.prepareChartSeries()
    }

这是我所拥有的: pic1

这是我想要的: pic2

1 个答案:

答案 0 :(得分:1)

使用格式化函数作为工具提示,如果少于两点则返回 false。示例:

    tooltip: {
        shared: true,
        formatter: function(tooltip) {
            if (this.points.length < 2) {
                return false;
            }

            return tooltip.defaultFormatter.call(this, tooltip);
        }
    }

现场演示: http://jsfiddle.net/BlackLabel/zrse9cdj/

API 参考: https://api.highcharts.com/highcharts/tooltip.formatter

相关问题