Stacked bar

author(s): Torstein Hønsi

by Guillaume Seguin

HTML

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

<figure class="highcharts-figure">
    <div id="container"></div>
</figure>

CSS

.highcharts-figure, .highcharts-data-table table {
    min-width: 310px; 
    max-width: 800px;
    margin: 1em auto;
}

#container {
    height: 400px;
}

.highcharts-data-table table {
	font-family: Verdana, sans-serif;
	border-collapse: collapse;
	border: 1px solid #EBEBEB;
	margin: 10px auto;
	text-align: center;
	width: 100%;
	max-width: 500px;
}
.highcharts-data-table caption {
    padding: 1em 0;
    font-size: 1.2em;
    color: #555;
}
.highcharts-data-table th {
	font-weight: 600;
    padding: 0.5em;
}
.highcharts-data-table td, .highcharts-data-table th, .highcharts-data-table caption {
    padding: 0.5em;
}
.highcharts-data-table thead tr, .highcharts-data-table tr:nth-child(even) {
    background: #f8f8f8;
}
.highcharts-data-table tr:hover {
    background: #f1f7ff;
}

JavaScript

Highcharts.chart('container', {
    chart: {
        type: 'bar'
    },
    title: {
        text: 'Comparaisons avec les biens comparables'
    },
    xAxis: {
        categories: ['<b>Vendus</b>', '<b>Sur le marché</b>', '<b>Invendus</b>']
    },
    yAxis: {
        min: 7000,
        title: {
            text: '<b>Prix au m²</b>'
        },
        plotLines: [
        {
          color: '#dc3545', // Red
          width: 2,
          zIndex: 4,
          value: 8000 // Position, you'll have to translate this to the values on your x axis
    		},
        {
          color: "#497cb1",
          width: 2,
          zIndex: 4,
          value: 7345 // Position, you'll have to translate this to the values on your x axis
    		}
      ]
    },
    plotOptions: {
        series: {
            stacking: 'normal',
        }
    },
    series: [
    {
        name: 'Fourchette haute',
        data: [800, 1000, 1200],
        color: '#ff8a84'
        
    }, {
        name: 'Fourchette intermédiaire',
        data: [1600, 600, 1000],
        color: '#fef8a0'
    }, {
        name: 'Fourchette basse',
        data: [500, 1200, 1000],
        color: '#aedd94'
    },
    {
        name: '',
        data: [6845, 7189, 7623],
        color: 'rgba(227, 24, 55, .0)',

    },
    { 
       	name: 'Estimation',
        color: '#497cb1',
    },
    { 
       	name: 'Prix de vente',
        color: '#dc3545',
    }]
});