Javascript 高寿期叠加
我想做一个有年龄间隔的叠层柱状图Javascript 高寿期叠加,javascript,highcharts,stacked-chart,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
我有一个二维数组,包含一个年龄键和一个值
其思想是:每个年龄段在其间隔内相互叠加,从而在单个列中表示该年龄段内的累积人数
我想用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?! --- */ }]
});
那么,考虑到我的二维数组,我如何可视化这个堆叠的柱状图呢
非常感谢您的帮助。:) 你需要对你的
数组进行分析,与你的限制(类别)进行比较,然后选择正确的数组
请参阅解析器(),希望它是正确的。或其他解决方案,为条形图的每个部分使用不同的序列:
var范围=[12,18,23,28,35,42,50,1000],
rangesLen=ranges.length,
系列=[];
$。每个(范围、功能(即){
为图例推送({//create series'容器
id:e+“索引”,
姓名:e
});
});
$。每个(年龄数据、功能(即,e){
var x=e[0],
y=e[1],
指数=0;
while(ranges[index]
不过,我认为塞巴斯蒂安的解决方案更快。我首先关心的是,每个年龄都必须是一个系列,这意味着每个系列只有一个非零条目。这不一定是错的,但似乎并不理想。
var ranges = [12, 18, 23, 28, 35, 42, 50, 1000],
rangesLen = ranges.length,
series = [];
$.each(ranges, function(i, e){
series.push({ //create series' containers for legend
id: e+'index',
name: e
});
});
$.each(ageData, function(i, e){
var x = e[0],
y = e[1],
index = 0;
while(ranges[index] < x){ // get category index
index ++;
}
series.push({
showInLegend: false,
linkedTo: ranges[index] +'index', // link to container series
data: [ [index, y] ] //add point at specific category
})
});