之前用win chart中的用Paint事件绘制了一些辅助线,如图
代码为
private void c1Chart1_Paint(object sender, PaintEventArgs e)
{
if (call)
{
Font font = new Font(FontFamily.GenericSansSerif.Name, 9);
System.Drawing.Pen pen = System.Drawing.Pens.Black;
System.Drawing.Graphics ghs = e.Graphics;
SizeF sf = ghs.MeasureString("1983", font);
Pen dashPen = new Pen(Color.Gray);
dashPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
float height = sf.Height - 2f;
float stringWidth = sf.Width;
Font smallFont = new Font(FontFamily.GenericSansSerif.Name, 8);
ghs.DrawLine(pen, new PointF(xcor1, ycor1 + height), new PointF(xcor2, ycor2 + height));
for (int i = 0; i < cors.GetLength(0); i++)
{
PointF beforePoint1 = new PointF(cors[i, 0], ycor1);
PointF beforePoint2 = new PointF(cors[i, 0], ycor1 + height);
PointF beforeHighPoint = new PointF(cors[i, 0], ycor_yMax);
PointF lastHighPoint = new PointF(cors[i, 1], ycor_yMax);
PointF lastPoint1 = new PointF(cors[i, 1], ycor1);
PointF lastPoint2 = new PointF(cors[i, 1], ycor1 + height);
ghs.DrawLine(pen, beforePoint1, beforePoint2);
ghs.DrawLine(pen, lastPoint1, lastPoint2);
ghs.DrawLine(dashPen, beforeHighPoint, beforePoint1);
ghs.DrawLine(dashPen, lastHighPoint, lastPoint1);
//显示年份
float distance = cors[i, 1] - cors[i, 0];
if (distance >= stringWidth)
{
float startXCor = cors[i, 0] + (distance - stringWidth) / 2.0f;
float startYCor = ycor1 + 0.2f;
ghs.DrawString((minYear + i).ToString(), smallFont, Brushes.Black, new PointF(startXCor, startYCor));
}
}
ghs.Save();
}
}
在wpf chart中没找到相关事件,不知道怎么实现,求解决。 |