面积图在高图中重叠,重叠点表现奇怪

时间:2017-03-31 08:21:20

标签: javascript highcharts

小提琴:http://jsfiddle.net/nz343opa/

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Stacked Area Chart</title>
    <script src="https://code.highcharts.com/highcharts.js"></script>
    <script src="https://code.highcharts.com/modules/exporting.js"></script>

</head>
<body>
    <div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
</body>
<script>
        Highcharts.chart('container', {
            chart: {
                type: 'area'
            },
            title: {
                text: 'Historic and Estimated Worldwide Population Growth by Region'
            },
            subtitle: {
                text: 'Source: Wikipedia.org'
            },
            xAxis: {
                categories: ['1750', '1800', '1850', '1900', '1950', '1999', '2050'],
                tickmarkPlacement: 'on',
                title: {
                    enabled: false
                }
            },
            yAxis: {
                title: {
                    text: 'Billions'
                },
                labels: {
                    formatter: function () {
                        return this.value / 1000;
                    }
                }
            },
            tooltip: {
                split: true,
                valueSuffix: ' millions'
            },
            plotOptions: {
                area: {
                    stacking: 'normal',
                    lineColor: '#666666',
                    lineWidth: 1,
                    marker: {
                        lineWidth: 1,
                        lineColor: '#666666'
                    }
                }
            },
            series: [{
                name: 'Asia',
                data: [502, 635, 809, 947, null, null, null]
            }, {
                name: 'Asia2',
                data: [null, null, null, 947, 800, 767, 1766]
            }, {
                name: 'Europe',
                data: [163, 203, 276, 408, null, null, null]
            }, {
                name: 'Europe2',
                data: [null, null, null, 408, 339, 818, 1201]
            }]
        });
    </script>
</html>

目前堆积区域图表的表现正如预期,但1990年的点数在偏远地区已经过时了。

这通常适用于非堆积区域图表,例如这个小提琴:http://jsfiddle.net/D4sbc/95/

有没有人知道使用highcharts堆积区域是否可以采取这种行为?

1 个答案:

答案 0 :(得分:0)

这是因为在位置3上您定义了4个点,这些点在堆积图表中移位。如果要拆分堆叠,则需要定义series.stack属性。

  series: [{
            name: 'Asia',
            data: [502, 635, 809, 947, null, null, null],
        stack: 0
        }, {
            name: 'Asia2',
            data: [null, null, null, 947, 800, 767, 1766],
        stack: 1
        }, {
            name: 'Europe',
            data: [163, 203, 276, 408, null, null, null],
        stack: 0
        }, {
            name: 'Europe2',
            data: [null, null, null, 408, 339, 818, 1201],
        stack: 1
        }]

示例:http://jsfiddle.net/nz343opa/1/