javascript - Highcharts 年龄堆叠

标签 javascript highcharts stacked-chart

我想制作一个带有年龄间隔的堆积柱形图。
我有一个包含年龄键和值的二维数组。
这个想法是:每个年龄在其区间内彼此堆叠,从而在单个列中表示该年龄区间内的累积人数。

我想通过 highcharts 的堆积柱形图示例来实现此解决方案。

这是我到目前为止的代码:

// Age stacked column chart.
        var ageData = [
            [0, 0], [1, 0], [2, 0], [3, 0], [4, 0], [5, 0], [6, 0], [7, 0], [8, 4], [9, 3],
            [10, 24], [11, 33], [12, 31], [13, 21], [14, 61], [15, 42], [16, 43], [17, 87], [18, 64], [19, 120],
            [20, 134], [21, 142], [22, 184], [23, 221], [24, 234], [25, 211], [26, 198], [27, 94], [28, 79], [29, 34],
            [30, 24], [31, 27], [32, 32], [33, 21], [34, 4], [35, 7], [36, 11], [37, 5], [38, 3], [39, 6],
            [40, 3], [41, 4], [42, 13], [43, 6], [44, 4], [45, 3], [46, 1], [47, 2], [48, 2], [49, 0],
            [50, 0], [51, 34]]
        $('#container_stackedColumn').highcharts({
            chart: {
                type: 'column'
            },
            title: {
                text: 'User age distribution'
            },
            xAxis: {
                categories: [
                    '0-12',
                    '13-18',
                    '19-23',
                    '24-28',
                    '29-35',
                    '36-42',
                    '43-50',
                    '>50'
                ]
            },
            yAxis: {
                min: 0,
                title: {
                    text: 'Number of users'
                },
                stackLabels: {
                    enabled: true,
                    style: {
                        fontWeight: 'bold',
                        color: (Highcharts.theme && Highcharts.theme.textColor) || 'gray'
                    }
                }
            },
            plotOptions: {
                column: {
                    stacking: 'normal',
                    dataLabels: {
                        enabled: true,
                        color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white',
                        style: {
                            textShadow: '0 0 3px black, 0 0 3px black'
                        }
                    }
                }
            },
            series: [{ /* --- What to do here?! --- */ }]
        });

那么,考虑到我的二维数组,如何可视化这个堆积柱形图?

非常感谢任何帮助。 :)

最佳答案

您需要迭代数组,与您拥有的限制(类别)进行比较,然后推送到正确的系列数组。

查看解析器( http://jsfiddle.net/W6AFY/3/ )希望它是正确的。

关于javascript - Highcharts 年龄堆叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24589376/

相关文章:

javascript - Hangman jQuery 函数

javascript - 路由更改时如何滚动回元素?

javascript - Node 中的 Highcharts

r - 没有 facet_grid 的分组堆叠条形图 ggplot2

python - 条件工具提示 Bokeh 堆积图

python - Pandas 绘制 3 个变量的图

javascript - JSplumb 双键

javascript - 使用 React.js 时未定义 Web Speech API SpeechRecognition

javascript - Highcharts 列区域

google-chrome - Highcharts - 工具提示和系列名称在 chrome 中是开箱即用的