Transform axis value to pixel value and vice versa
SfChart offers two utility methods for converting your data points into pixel values (device coordinates).
- ValueToPoint(ChartAxis axis, double value)
- PointToValue(ChartAxis axis, Point point)
private void LineChart_MouseMove(object sender, MouseEventArgs e)
{
Point mousePoint = new Point
{
X = e.GetPosition(LineChart).X - LineChart.SeriesClipRect.Left - LineChart.Margin.Left,
Y = e.GetPosition(LineChart).Y - LineChart.SeriesClipRect.Top - LineChart.Margin.Top
};
// Converts mouse co-ordinate points into a value related to ChartAxis.
double xValue = this.LineChart.PointToValue(this.LineChart.PrimaryAxis, mousePoint);
double yValue = this.LineChart.PointToValue(this.LineChart.SecondaryAxis, mousePoint);
// Converts the data point value of the chart to Chart coordinate.
double chartPointX = this.LineChart.ValueToPoint(this.LineChart.PrimaryAxis, xValue);
double chartPointY = this.LineChart.ValueToPoint(this.LineChart.SecondaryAxis, yValue);
}
Was this page helpful?
Yes
No
Thank you for your feedback!
Thank you for your feedback and comments. We will rectify this as soon as possible!
An unknown error has occurred. Please try again.
Help us improve this page