user1050619
user1050619

Reputation: 20856

Display Stack label Highcharts

Im using the stacked charts from Highcharts but would like to include the stack name below the stacked bar charts.

http://jsfiddle.net/gh/get/jquery/1.9.1/highslide-software/highcharts.com/tree/master/samples/highcharts/demo/column-stacked-and-grouped/

js

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

        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'
        }]
    });
});

Iin this chart, I want to show 'MALE' & 'FEMALE' below the stack.

How can I do it using Highcharts

Something like below..Where you display the stack name - "Maintenance", "other" and "peak"

enter image description here

Upvotes: 0

Views: 2137

Answers (1)

Grzegorz Blachliński
Grzegorz Blachliński

Reputation: 5222

I think that in your case you may use grouped-categories plugin. You may find this plugin on a Highcharts plugins repository: http://www.highcharts.com/plugin-registry/single/11/Grouped-Categories

$(function() {
  var chart = new Highcharts.Chart({
    chart: {
      renderTo: "container",
      type: "column",
    },
    plotOptions: {
      series: {
        stacking: 'normal'
      }
    },
    series: [{
      data: [4, 14, 18, 5, 6, 5]
    }, {
      data: [4, 14, 18, 5, 6, 5]
    }, {
      data: [4, 14, 18, 5, 6, 5]
    }],
    xAxis: {
      categories: [{
        name: "Fruit",
        categories: ["Apple", "Banana"]
      }, {
        name: "Vegetable",
        categories: ["Carrot", "Potato"]
      }, {
        name: "Fish",
        categories: ["Cod", "Salmon"]
      }]
    }
  });
});

And here you can find simple example how your chart may work with this plugin: http://jsfiddle.net/TFhd7/943/

Upvotes: 1

Related Questions