我应该在极坐标图中画一个圆圈,上面有一些文字。
我开始使用 PostPaint,获得了图表图形,因此我能够在上面绘制和编写自定义内容。
我的主要问题是位置。
例如。我想在 x 和 y 轴交叉的地方绘制 sg ,但我没有找到任何有效的方法将图形坐标(在我的示例中为 0,0)转换为像素坐标。
我怎样才能做到这一点?如何将图表坐标转换为像素?
.net4/winforms/vs2010/c#
所以,我解决了。
我处理 mschart 的 postpaint 事件:
private void chartMain_PostPaint(object sender, ChartPaintEventArgs e)
{
try
{
if (chartMain.ChartAreas.FirstOrDefault(a=>a.Name == "Default") == null)
return;
Graphics graph = e.ChartGraphics.Graphics;
var day = Date.GetBoundaries(daySelectorMain.DateTimePickerDay.Value);
var toDate = day.Item2; //it is maxdate value (max value of x axis)
var centerY = (float)chartMain.ChartAreas["Default"].AxisY.ValueToPixelPosition(-80); //-80 is the min value of y (y axis)
var centerX = (float)chartMain.ChartAreas["Default"].AxisX.ValueToPixelPosition(toDate.ToOADate());
var origoY = (float)chartMain.ChartAreas["Default"].AxisY.ValueToPixelPosition(0);
var origoX = (float)chartMain.ChartAreas["Default"].AxisX.ValueToPixelPosition(toDate.ToOADate());
var radius = (float)(centerY - origoY) - 1;
graph.DrawLine(System.Drawing.Pens.Blue,
new PointF(origoX, origoY),
new PointF(centerX, centerY));
graph.FillEllipse(new SolidBrush(Color.White), centerX - radius, centerY - radius, radius * 2, radius * 2);
}
catch (System.Exception exc)
{
Debug.Assert(false, exc.Message);
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)