[英]MS Chart axes are drawn trough data points
I'm working with MS Charts, and somehow I can't figure out a way to draw the points on top of the y-axis.我正在使用 MS 图表,不知何故我无法找到一种在 y 轴顶部绘制点的方法。 As you can see in the image below, the points at x = 0 (label 1998) are below the Y-axis.如下图所示,x = 0(标签 1998)处的点位于 Y 轴下方。 Does anyone recognize this problem?有没有人认识到这个问题? Has it something to do with order of prepaint and postpaint events?它与绘制前和绘制后事件的顺序有关吗?
EDIT: Test with custom drawn dots, only until the y-axis..编辑:使用自定义绘制的点进行测试,直到 y 轴..
In a Chart
all DataPoints
go over the GridLines
but under the Axes
and the TickMarks
.在Chart
的所有DataPoints
越过GridLines
,但下Axes
和TickMarks
。
To paint them over the Axes
as well you need to owner draw them in one of the Paint
events.要画他们在Axes
,以及你需要所有人画在一个Paint
事件。
This is simple if your ChartType
is of type Points
, Spline
or Line
and your MarkerType
of Circle
or Rectangle
.如果您的ChartType
是Points
、 Spline
或Line
类型并且您的MarkerType
是Circle
或Rectangle
,那么这很简单。
For most other types like Column
or Bar
etc this is a lot harder.对于大多数其他类型,如Column
或Bar
等,这要困难得多。
Here is a simple example for Points
;这是Points
一个简单示例; pick a size you like better..!选择你更喜欢的尺码..!
private void chart1_PostPaint(object sender, ChartPaintEventArgs e)
{
if (chart1.Series.Count == 0) return;
Axis AX = chart1.ChartAreas[0].AxisX;
Axis AY = chart1.ChartAreas[0].AxisY;
chart1.ApplyPaletteColors();
foreach (Series s in chart1.Series)
foreach (DataPoint dp in s.Points)
{
float x = (float )AX.ValueToPixelPosition(dp.XValue);
float y = (float )AY.ValueToPixelPosition(dp.YValues[0]);
float w2 = 3.6f;
using (SolidBrush brush = new SolidBrush(Color.YellowGreen))
e.ChartGraphics.Graphics.FillEllipse(brush,
x - w2, y - w2, w2 * 2f, w2 * 2f);
}
}
I have suppressed the custom drawing for some points.我已经抑制了某些点的自定义绘图。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.