我想用Microsoft的Chart Controls创建一个图表,它看起来像这个Excel图表: 有人知道如何将x轴上的元素分组为此图像吗?
到目前为止我做的是:
Series s = new Series("Testseries");
s.ChartType = SeriesChartType.Line;
s.Color = Color.Red;
s.Points.Add(20,65);
s.Points.Add(17,66);
s.Points.Add(17,55);
Chart1.Series.Add(s);
如何在x轴上单独标记每个数据点?
答案 0 :(得分:3)
好的,我解决了这个问题:
string[] xval = { "ElementX", "ElementX", "ElementX", "ElementX", "ElementX", "ElementX", "ElementX", "ElementX", "ElementX", "ElementX", "ElementX", "ElementX", "ElementX", "ElementX", "ElementX", "ElementX", "ElementX", "ElementX", "ElementX", "ElementX", "ElementX" };
for (int i = 0; i < xval.Length; i++)
{
Chart1.ChartAreas["ChartArea1"].AxisX.CustomLabels.Add(i + 0.5, i + 1.5, xval[i]);
Chart1.ChartAreas["ChartArea1"].AxisX.CustomLabels[i].GridTicks = GridTickTypes.TickMark;
}
// second label row
Chart1.ChartAreas["ChartArea1"].AxisX.CustomLabels.Add(0, 5.5, "Group1", 1, LabelMarkStyle.LineSideMark);
Chart1.ChartAreas["ChartArea1"].AxisX.CustomLabels.Add(5.5, 12.5, "Group2", 1, LabelMarkStyle.LineSideMark);
Chart1.ChartAreas["ChartArea1"].AxisX.CustomLabels.Add(12.5, 21.5, "Group3", 1, LabelMarkStyle.LineSideMark);