网点图-堆叠两个系列,留下其他作为正常的条形图

本文关键字:其他 条形图 -堆 个系列 | 更新日期: 2023-09-27 18:13:12

我有一个3系列的点阵图。我可以把整个图的样式改为堆叠。

ChartIn.YAxis.Scale = Scale.Stacked;

但是我只想把三个级数中的两个叠起来。因此,对于每一个都有两个条组合成一个堆栈,旁边是另一个完整的条。

这能做到吗?

网点图-堆叠两个系列,留下其他作为正常的条形图

最后,我将我想要的数据从堆栈中分离到一个单独的填充行系列中。不理想,但看起来不错。

ChartThree.SeriesCollection[3].Type = SeriesType.AreaLine;

实现这一点的方法是创建一个额外的比例,并将额外的系列的y轴设置为该比例。第二个刻度可以独立于第一个刻度是否堆叠。请注意,您需要调整第二个刻度的范围,以使值以正确的相对大小显示。

下面是一个示例,生成了一个包含两个单独堆叠数据集的图表(使用之前总共填充了4个系列的图表):

//set main chart to stacked
Chart.YAxis.Scale = Scale.Stacked; 
//create new axis, assign it to relevant series, and set it's scale to stacked
Axis a2 = new Axis();
Chart.SeriesCollection[2].YAxis = a2;
Chart.SeriesCollection[3].YAxis = a2;
a2.Scale = Scale.Stacked;
//tie the scales together to ensure proper relative display
Chart.YAxis.SynchronizeScale.Add(a2);