HighCharts每个类别多个数据点

HighCharts multiple data points per category

本文关键字:数据 HighCharts      更新时间:2023-09-26

我希望将多个数据点绘制在类别上。在下面的示例案例中,对于"一月"月份,我想绘制多个数据点而不是一个。类似于 [20,28] 在同一垂直线上。请看我为东京和一月准备的系列。我想传递一个数据点数组而不是单个数据点。(示例 [20,28] 而不是 28)

$(function () {
    $('#container').highcharts({
        chart: {
            type: 'scatter'
        },
        title: {
            text: 'Monthly Average Temperature'
        },
        subtitle: {
            text: 'Source: WorldClimate.com'
        },
        xAxis: {
            categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
        },
        yAxis: {
            title: {
                text: 'Temperature (°C)'
            }
        },
        plotOptions: {
            line: {
                dataLabels: {
                    enabled: true
                },
                enableMouseTracking: false
            }
        },
        series: [{
            name: 'Tokyo',
            data: [[20,28], 6.9, 9.5, 14.5, 18.4, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]
        }, {
            name: 'London',
            data: [3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8]
        }]
    });
});

您可以使用以下方法将数据点绘制到同一垂直方向。

$(function () {
     $('#container').highcharts({
        chart: {
            type: 'scatter'
        },
        title: {
            text: 'Monthly Average Temperature'
        },
        subtitle: {
            text: 'Source: WorldClimate.com'
        },
        xAxis: {
            categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
            title: {
                text: 'Months'
            }
        },
        yAxis: {
            title: {
                text: 'Temperature (°C)'
            }
        },
        plotOptions: {
            line: {
                dataLabels: {
                    enabled: true
                },
                enableMouseTracking: false
            }
        },
        series: [{
            name: 'Tokyo',
            data: [[0, 20], [0, 28], [1, 6.9], [2, 9.5],[3, 14.5],[4, 18.4], [5, 21.5], [6, 25.2], [7, 26.5], [8, 23.3], [9, 18.3], [10, 13.9], [11, 9.6]]
        }, {
            name: 'London',
            data: [3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8]
        }]
    });
});
<script src="https://code.jquery.com/jquery-2.2.1.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<div id="container" style="min-width: 310px; height: 400px; max-width: 800px; margin: 0 auto"></div>