Highcharts Histogram

by amrutaJgtp

HTML

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

<figure class="highcharts-figure">
    <div id="container"></div>
    <p class="highcharts-description">
        Chart showing how Highcharts can automatically compute a histogram from
        source data. In this chart, the source data is also displayed as a
        scatter plot.
    </p>
</figure>

CSS

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

.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

const data = [
    {
        "eQCategoryValue": "94-104",
        "y": 99.57575757575758
    },
    {
        "eQCategoryValue": "83-94",
        "y": 90.5576923076923
    },
    {
        "eQCategoryValue": "73-83",
        "y": 79.17307692307692
    },
    {
        "eQCategoryValue": "63-73",
        "y": 69.8936170212766
    },
    {
        "eQCategoryValue": "53-63",
        "y": 59
    },
    {
        "eQCategoryValue": "43-53",
        "y": 48.75
    },
    {
        "eQCategoryValue": "33-43",
        "y": 35.47540983606557
    },
    {
        "eQCategoryValue": "22-33",
        "y": 26.6
    },
    {
        "eQCategoryValue": "2-12",
        "y": 7.280701754385965
    },
    {
        "eQCategoryValue": "12-22",
        "y": 18.17241379310345
    }
];

Highcharts.chart('container', {
    title: {
        text: 'Highcharts Histogram'
    },

    xAxis: [{
    		categories: ["94-104","83-94","73-83","63-73","53-63","43-53","33-43","22-33","2-12","12-22"],
        title: { text: 'Data' },
        alignTicks: false
    }, {
        title: { text: 'Histogram' },
        alignTicks: false,
        opposite: true
    }],

    yAxis: [{
        title: { text: 'Data' }
    }, {
        title: { text: 'Histogram' },
        opposite: true
    }],

    /*plotOptions: {
        histogram: {
            accessibility: {
                point: {
                    valueDescriptionFormat: '{index}. {point.x:.3f} to ' +
                        '{point.x2:.3f}, {point.y}.'
                }
            }
        }
    },*/

    series: [{
        name: 'Histogram',
        type: 'histogram',
        xAxis: 1,
        yAxis: 1,
        baseSeries: 's1',
        zIndex: -1
    }, {
        name: 'Data',
        type: 'line',
        data: data,
        id: 's1'
    }]
});