MSChart中的删除行
本文关键字:删除行 MSChart | 更新日期: 2023-09-27 18:19:29
我在C#程序中使用MSChart创建折线图,但找不到任何创建"下降线"的选项,即从每个数据点下降到X轴的线。有人能帮忙吗?谢谢
我使用LineAnnotation对象解决了问题:
int index = 1;
foreach (DataPoint _point in series1.Points)
{
LineAnnotation annotation = new LineAnnotation();
annotation.LineColor = Color.Black;
annotation.LineWidth = 4;
annotation.LineDashStyle = ChartDashStyle.Dot;
annotation.AxisX = chartArea1.AxisX;
annotation.AxisY = chartArea1.AxisY;
annotation.AnchorX = index;
annotation.AnchorY = 0;
annotation.Height = _point.YValues[0];
annotation.Width = 0;
annotation.IsSizeAlwaysRelative = false;
annotation.ClipToChartArea = "ChartArea1";
chart1.Annotations.Add(annotation);
index++;
}
有趣的是,当我将注释锚定到数据点本身时,上面的代码表现得很奇怪,即使我的所有点都在同一象限中,也会向上画一些线,向下画一些线。经过多次尝试,我设法通过将注释锚定在X轴上适当的"下降"点来解决问题。