我希望能够显示4组数据。每组有1个堆叠列,1个非堆叠列。这是我所追求的模型:
获得四个小组很容易,这给了我想要的东西:
Series series = chart.Series.Add("Budget");
series.ChartType = SeriesChartType.Column;
series.Name = "Budget";
series.Points.Add(55);
series.Points.Add(10);
series.Points.Add(50);
series.Points.Add(50);
series = chart.Series.Add("Actual");
series.ChartType = SeriesChartType.Column;
series.Name = "Actual";
series.Points.Add(80);
series.Points.Add(90);
series.Points.Add(10);
series.Points.Add(10);
现在我想把黄色条棒叠起来。我已经尝试过添加3个系列; ChartType = Column,StackedColumn,StackedColumn。但堆叠的列出现在非堆叠的列的前面。
我正在尝试的是什么?
答案 0 :(得分:2)
在系列调用CustomPropertiesMethod并为组分配不同的StackedGroupNames,例如,如果您希望系列1和2堆叠但希望系列3位于旁边
Series1.CustomProperties = "StackedGroupName=Group1";
Series2.CustomProperties = "StackedGroupName=Group1";
Series3.CustomProperties = "StackedGroupName=Group2";
答案 1 :(得分:0)
我可能错了,但系列按照添加的顺序显示。
答案 2 :(得分:0)
我接近它的方式是假装X轴数据,因此它在“真实”的两侧偏移。点,然后使用自定义标签。我不容易粘贴。测试代码,但我认为它是这样的:
double pointWidth = 0.375;
double pointOffset = pointWidth * 0.5;
// Add first series - column
_Chart.Add("Series1");
_Chart.Series["Series1"].ChartType = SeriesChartType.Column;
_Chart.Series["Series1"]["PointWidth"] = pointWidth.ToString();
for (int ii = 0; ii < 10; ii++)
{
_Chart.Series["Series1"].Points.AddXY(ii - pointOffset, YourYValueHere);
}
// Add second series - stacked column
_Chart.Add("Series2");
_Chart.Series["Series2"].ChartType = SeriesChartType.Column;
_Chart.Series["Series2"]["PointWidth"] = pointWidth.ToString();
for (int ii = 0; ii < 10; ii++)
{
_Chart.Series["Series2"].Points.AddXY(ii + pointOffset, YourYValueHere);
}
// Add thrid series - stacked column
_Chart.Add("Series3");
_Chart.Series["Series3"].ChartType = SeriesChartType.Column;
_Chart.Series["Series3"]["PointWidth"] = pointWidth.ToString();
for (int ii = 0; ii < 10; ii++)
{
_Chart.Series["Series3"].Points.AddXY(ii + pointOffset, YourYValueHere);
_Chart.ChartAreas["Area1"].AxisX.CustomLabels.Add(
ii - 0.5, ii + 0.5, ii);
}
_Chart.ChartAreas["Area1"].AxisX.Minimum = -0.5;
_Chart.ChartAreas["Area1"].AxisX.Maximum =
_Chart.Series["Series3"].Points.Count - 0.5;
_Chart.ChartAreas["Area1"].AxisX.LabelStyle.IsEndLabelVisible = true;
_Chart.ChartAreas["Area1"].AxisX.IsMarginVisible = false;
如果StackedGroupName的工作原理,那么它会更简单。我试试吧。