Current filter:
                                You should refresh the page.

                                How to convert axis values of series points into screen coordinates

                                0

                                This example demonstrates how you can obtain screen coordinates of series points (as opposed to their diagram coordinates measured in axis units), and draw a geometric figure across these points.

                                This is done in the ChartControl.CustomPaint event handler, by calling the DiagramToPoint method of the chart's XYDiagram2D object.

                                You must  log in  or  register  to leave comments
                                Select file
                                • Form1.cs
                                Select language
                                • C#
                                • VB.NET
                                Select version
                                • v2012 vol 1.5 - v2013 vol 1.2
                                • v2010 vol 2.3 - v2011 vol 2.14
                                using System;
                                using System.Drawing;
                                using System.Windows.Forms;
                                using System.Drawing.Drawing2D;
                                using System.Collections.Generic;
                                using DevExpress.XtraCharts;
                                // ...
                                
                                namespace CustomPaintEvent {
                                    public partial class Form1 : Form {
                                        public Form1() {
                                            InitializeComponent();
                                        }
                                
                                        private void chartControl1_CustomPaint(object sender, CustomPaintEventArgs e) {
                                            ChartControl chart = (ChartControl)sender;
                                            Series series = chart.Series[0];
                                
                                            Point[] screenPoints = new Point[series.Points.Count];
                                
                                            for (int i = 0; i < series.Points.Count; i++) {
                                                screenPoints[i] =
                                                    ((XYDiagram2D)chart.Diagram).DiagramToPoint(series.Points[i].Argument,
                                                    series.Points[i].Values[0]).Point;
                                            }
                                
                                            Graphics g = e.Graphics;
                                            g.SmoothingMode = SmoothingMode.AntiAlias;
                                            g.FillPolygon(new SolidBrush(Color.LightGreen), screenPoints);
                                            g.DrawPolygon(new Pen(Color.DarkGreen, 2), screenPoints);
                                        }
                                
                                    }
                                }