【问题标题】:Type Labels on Stacked and grouped column - Highcharts堆叠和分组列上的类型标签 - Highcharts
【发布时间】:2017-12-05 21:15:19
【问题描述】:

我正在尝试获取堆叠条形图上的标签。这里的堆栈类型是男性/女性,我想在图表上显示。到底有没有可以展示的?

这是链接

https://jsfiddle.net/jq2e51Lx/

这是 html:

<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>

<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>

Javascript

Highcharts.chart('container', {

    chart: {
        type: 'column'
    },

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

    xAxis: {
        categories: ['Apples', 'Oranges', 'Pears', 'Grapes', 'Bananas']
    },

    yAxis: {
        allowDecimals: false,
        min: 0,
        title: {
            text: 'Number of fruits'
        }
    },

    tooltip: {
        formatter: function () {
            return '<b>' + this.x + '</b><br/>' +
                this.series.name + ': ' + this.y + '<br/>' +
                'Total: ' + this.point.stackTotal;
        }
    },

    plotOptions: {
        column: {
            stacking: 'normal'
        }
    },

    series: [{
        name: 'John',
        data: [5, 3, 4, 7, 2],
        stack: 'male'
    }, {
        name: 'Joe',
        data: [3, 4, 4, 2, 5],
        stack: 'male'
    }, {
        name: 'Jane',
        data: [2, 5, 6, 2, 1],
        stack: 'female'
    }, {
        name: 'Janet',
        data: [3, 0, 4, 4, 3],
        stack: 'female'
    }]
});

【问题讨论】:

标签: highcharts labels stacked-chart


【解决方案1】:

The OP wrote in a comment:

非常感谢!,就像一个魅力:)

基于@Barbara Laird 的小提琴样本

Highcharts.chart('container', {
  chart: {
    type: 'column'
  },
  title: {
    text: 'Total fruit consumtion, grouped by gender'
  },
  xAxis: {
    categories: ['Apples', 'Oranges', 'Pears', 'Grapes', 'Bananas'],
    labels: {
      y: 40
    }
  },
  yAxis: {
    allowDecimals: false,
    min: 0,
    title: {
      text: 'Number of fruits'
    },
    stackLabels: {
      enabled: true,
      verticalAlign: 'bottom',
      crop: false,
      overflow: 'none',
      y: 20,
      formatter: function() {
        return this.stack;
      },
      style: {
        fontSize: '9px'
      }
    }
  },
  legend: {
    labelFormatter: function() {
      return this.name + ' (' + this.userOptions.stack + ')';
    }
  },
  tooltip: {
    formatter: function() {
      var stackName = this.series.userOptions.stack;

      return '<b>Stack name: </b>' + stackName + '<br/><b>' + this.x + '</b><br/>' +
        this.series.name + ': ' + this.y + '<br/>' +
        'Total: ' + this.point.stackTotal;
    }
  },
  plotOptions: {
    column: {
      stacking: 'normal'
    }
  },
  series: [{
    name: 'John',
    data: [5, 3, 4, 7, 2],
    stack: 'male'
  }, {
    name: 'Joe',
    data: [3, 4, 4, 2, 5],
    stack: 'male'
  }, {
    name: 'Jane',
    data: [2, 5, 6, 2, 1],
    stack: 'female'
  }, {
    name: 'Janet',
    data: [3, 0, 4, 4, 3],
    stack: 'female'
  }]
});
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>

<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>

【讨论】:

    猜你喜欢
    • 2017-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-26
    相关资源
    最近更新 更多