Box plot

author(s): Torstein Hønsi

by kikkoma

HTML

<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/highcharts-more.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

#container {
    height: 400px; 
}

.highcharts-figure, .highcharts-data-table table {
    min-width: 300px; 
    max-width: 700px;
    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

Highcharts.chart('container', {

    chart: {
        type: 'boxplot'
    },

    title: {
        text: '統計區間 2020/6/1~2020/6/10'
    },

    legend: {
        enabled: false
    },

    xAxis: {
        categories: ['6/1', '6/2', '6/3', '6/4', '6/5','6/6','6/7','6/8','6/9','6/10'],
        title: {
            text: '颱風示警'
        }
    },

    yAxis: {
        title: {
            text: '評分統計'
        }       
    },

    series: [{
        name: '箱型線',
        data: [
            [2, 3.5, 4, 5, 5],
            [2.5, 2.5, 3.5, 4, 4],
            [3.5, 3.5, 4, 4, 5],
            [1, 1.5, 2.5, 4, 5],
            [4, 4, 4, 4, 4],
            [4, 4, 4, 4, 4],
            [3, 3, 4, 4, 5],
            [2, 2.5, 3.5, 4, 4],
            [4, 4, 4, 4, 4],
            [3, 3, 3.5, 4, 4]
        ],
        tooltip: {
            headerFormat: '<em>颱風示警 {point.key}</em><br/>'
        }
    },
    {
        type: 'spline',
        name: 'Average',
        data: [4.5, 3.7, 3.8, 3, 4,4,3.9,3.6,4,3.7],
        marker: {
            lineWidth: 2,
            lineColor: Highcharts.getOptions().colors[3],
            fillColor: 'white'
        },
        tooltip:{}
        }
    ]

});