【问题标题】:show Datalabels (total and dataLabel name) on a column chart- ReactJs highcharts在柱形图上显示 Datalabels(总数和 dataLabel 名称)-ReactJs highcharts
【发布时间】:2020-10-21 02:42:38
【问题描述】:

我正在使用按列分组的高图表。前任: https://jsfiddle.net/2bvudw1m/

有没有一种方法可以显示代表y 计数(列系列顶部)和列的dataLabel 名称(底部)的数据标签? 例如:这是我的系列数据:

 series: [{
      name: 'active',
      data: [53, 33, 43, 63, 7, 83],
       dataLabels: {
        enabled: true,
        verticalAlign: 'bottom',
        overflow: 'none',
        crop: false,
        y: 20,
        formatter() {
          return this.series.userOptions.name;
        }
      }
    
    }, {
      name: 'new',
      data: [33, 43, 43, 63, 73, 8],
     
    }]

我想展示两件事:

  1. 计数代表每个系列
  2. 该系列的DataLabel

到目前为止,我有这个:

 $(function() {
      $('#container').highcharts({

        chart: {
          type: 'column',
        },

        title: {
          text: 'Total fruit consumtion, grouped by gender'
        },

        xAxis: {
          categories: ['Apples', 'Oranges', 'Apples2', 'Oranges2','Apples3', 'Apple33'],
          offset: 30
        },
        yAxis: {
          allowDecimals: false,
          //offset:10,
          title: {
            text: 'Number of fruits'
          },
          stackLabels: {
            enabled: true,
            verticalAlign: 'top',
          }

        },

        plotOptions: {
        series: {
          dataLabels: {
            enabled: true,
            formatter: function() {
                return this.y;
            }
           }
         },
          column: {
            stacking: ''
          },
        },

        series: [{
          name: 'active',
          data: [53, 33, 43, 63, 7, 83],
           dataLabels: {
            enabled: true,
            verticalAlign: 'bottom',
            overflow: 'none',
            crop: false,
            y: 20,
            formatter() {
              return this.series.userOptions.name;
            }
          }
        
        }, {
          name: 'new',
          data: [33, 43, 43, 63, 73, 8],
         
        }
        ]
      });
    });

https://jsfiddle.net/nec89t56/2/

但是这不起作用,因为当我尝试添加两个值时,它要么添加 y 计数或名称。当列为grouped: true 和stacking: "" 时,有没有办法同时添加两者

注意:我不能像“正常”那样进行堆叠,因为它会堆叠而不是分组,这不是我想要的。

有什么想法吗?

【问题讨论】:

    标签: javascript highcharts


    【解决方案1】:

    您可以通过将dataLabels 定义为对象数组来添加多个dataLabels,其中每个对象都是每个数据标签的单独配置。

    演示:https://jsfiddle.net/BlackLabel/op4ehx8m/

    plotOptions: {
      series: {
        dataLabels: [{
          enabled: true,
          verticalAlign: 'bottom',
          overflow: 'none',
          crop: false,
          y: 20,
          formatter() {
            return this.series.userOptions.name;
          }
        }, {
          enabled: true
        }]
      },
      column: {
        stacking: ''
      },
    },
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多