Highcharts:在箱线图中显示标签(最小值,最大值,中位数等)

Highcharts : Display the labels (min, max, median etc.) in boxplot

本文关键字:最小值 最大值 中位数 标签 显示 Highcharts      更新时间:2023-09-26

我使用highcharts创建了一个基本的箱线图,当我将鼠标悬停在箱线图上时,它向我显示了最大值,最大四分位数,中位数,最小四分位数和最小值。我想以某种方式在每一行旁边的绘图中显示这些值。

我检查了api,发现"dataLabel"会有帮助,但这是不支持箱线图。有人能告诉我如何做到这一点吗?

谢谢。

不可能开箱即用,但正如Steve Gu提到的那样,可以通过scatter实现。您甚至可以忽略格式化器并完全禁用标记:

{
  series: [
    {
      type: 'scatter',
      tooltip: {
        enabled: false
      },
      dataLabels: {
        format: '{key}',
        enabled: true,
        y: 0,
      },
      data: [{ x: 0, y: 975, name: '975'}],
      marker: {
        enabled: false,
      }
    }
  ]
}

添加另一个数据系列,类型为"Scatter",并使用Marker将数据标签应用于该系列。窍门是使用与背景色相同的填充色和0线宽,这样标记将不可见,只有标签将显示。

{
        name: 'Outlier',
        color: 'white',
        type: 'scatter',
        data: [ // x, y positions where 0 is the first category
            {
                name: 'This is my label for the box',
                x:0,   //box index.  first one is 0.
                y:975 //it will be bigger than the maximum value of of the box
            }
        ],
        dataLabels : {
            align: 'left',
                enabled : true,
                formatter : function() {
                    return this.point.name;
                },
            y: 10,
            },
        marker: {
            fillColor: 'white',
            lineWidth: 0,
            lineColor: 'white'
        }
    }

不幸的是,这个选项是不支持的,只有你能做的是使用渲染器在图表中添加自定义文本,但我知道这可能是不舒服的解决方案。http://api.highcharts.com/highcharts Renderer.text ()

显然你可以在我们的用户语音系统http://highcharts.uservoice.com/中提出你的建议