简体   繁体   中英

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. As you can see in the image below, the points at x = 0 (label 1998) are below the Y-axis. 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.. 在此处输入图片说明

In a Chart all DataPoints go over the GridLines but under the Axes and the TickMarks .

To paint them over the Axes as well you need to owner draw them in one of the Paint events.

This is simple if your ChartType is of type Points , Spline or Line and your MarkerType of Circle or Rectangle .

For most other types like Column or Bar etc this is a lot harder.

Here is a simple example for 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM