javascript 如何防止我的堆叠系列顺序相反?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16186427/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to prevent my stacked series from being in reverse order?
提问by keskispas
I tried an example of stacked series on JSFiddlebut according to me, series are reversed when stacked:
我在 JSFiddle 上尝试了一个堆叠系列的例子,但据我说,堆叠时系列是相反的:
$(function () {
$('#container').highcharts({
chart: {
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
plotOptions: {
series: {
stacking: 'normal'
}
},
series: [{
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
}, {
data: [144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4, 29.9, 71.5, 106.4, 129.2]
}]
});
});
The first line in blue should be drawn first (January : 29.9), and the second should be added to this one (January : 29.9 + 144 = 173.9 ).
应该首先绘制蓝色的第一条线(一月:29.9),第二条应该添加到这条线中(一月:29.9 + 144 = 173.9)。
Is there a way to get series in the right order when they are stacked?
有没有办法在堆叠时以正确的顺序获得系列?
回答by lionel
Since this was the top result in google, maybe this saves time for some:
由于这是谷歌的最高结果,也许这可以为某些人节省时间:
The yAxis
has a reversedStacks
parameter (since version 3.0.10), which is true
by default. To build stacks from bottom up, set this to false
. Legend and shared tooltip item order remain correct this way.
该yAxis
有一个reversedStacks
参数(自3.0.10版本),这是true
默认。要自下而上构建堆栈,请将其设置为false
. 图例和共享工具提示项目顺序以这种方式保持正确。
回答by Sebastian Bochan
You can change order by index parameter which can be set in serie.
您可以通过可以在系列中设置的索引参数更改顺序。
series: [{
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4],
index:1
}, {
data: [144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4, 29.9, 71.5, 106.4, 129.2],
index:0
}]
回答by mt81
You can use the serie's legendIndexparameter : http://api.highcharts.com/highcharts#series.data.legendIndex
您可以使用该系列的legendIndex参数:http: //api.highcharts.com/highcharts#series.data.legendIndex
回答by Jfly
Another way of doing this is by adding .reverse()
to the end of the series array, see example at http://jsfiddle.net/sq9u6q5n/.
另一种方法是添加.reverse()
到系列数组的末尾,参见http://jsfiddle.net/sq9u6q5n/ 中的示例。
回答by Matt Sich
What you are looking for is reversed
in xAxis or yAxis. I tried reversedStacks
but it didn't work and after looking at the documentation, I couldn't find it so assuming that it has been replaced with reversed
.
您正在寻找的是reversed
xAxis 或 yAxis。我试过了,reversedStacks
但没有用,在查看文档后,我无法找到它,因此假设它已被替换为reversed
.