By Kevin Harrison - 4 Years Ago
|
Hi guys
We've added functionality where clicking on an axis (hitTestResult.ChartElement == ChartElement.Axis) brings up a context menu. We'd now like to test this by simulating a click in the axis area and therefore need to calculate x,y coordinates.
For points within the chart we already have private Point CartesianChartPixelCoordinates(NChart nevronChart, int horizontalAxisId, int verticalAxisId, double xValue, double yValue) { NScale2DToViewTransformation scale2DToViewTransformation = new NScale2DToViewTransformation(nevronControl.View.Context, nevronChart, horizontalAxisId, verticalAxisId); NPointF viewPoint = new NPointF(); scale2DToViewTransformation.Transform(new NVector2DD(xValue, yValue), ref viewPoint); return new Point((int) viewPoint.X, (int) viewPoint.Y); }
We could use this to click on the axis line (if we got the minimum value displayed on the axis) but is there is an alternative you can suggest to click on the axis label, for instance?
Thanks Kevin
|
By Nevron Support - 4 Years Ago
|
Hi Kevin,
You can assign a part id to different axis elements if you want to distinguish on which one of them the user clicked - this is illustrated by the following example: All Examples \ Interactivity \ Mouse Events \ Axes Hit Testing Scale Elements The following code shows how to use this approach: private void Form1_Load(object sender, EventArgs e) { NChart chart = nChartControl1.Charts[0]; NBarSeries bar = new NBarSeries(); bar.Values.Add(10); bar.Values.Add(20); bar.Values.Add(30); chart.Series.Add(bar); nChartControl1.MouseClick += NChartControl1_MouseClick; NLinearScaleConfigurator scaleY = (NLinearScaleConfigurator)chart.Axis(StandardAxis.PrimaryY).ScaleConfigurator; scaleY.LabelStyle.PartId = 1; } private void NChartControl1_MouseClick(object sender, MouseEventArgs e) { NHitTestResult result = nChartControl1.HitTest(e.X, e.Y); if (result.ChartElement == ChartElement.Axis) { // you clicked on the axis if (result.AxisScalePartId == 1) { // you clicked on a label NChart chart = nChartControl1.Charts[0]; NViewToScale1DTransformation viewToScale = new NViewToScale1DTransformation(null, chart, (int)StandardAxis.PrimaryY, (int)StandardAxis.PrimaryX); double value = 0; viewToScale.Transform(new Nevron.GraphicsCore.NPointF(e.X, e.Y), ref value); MessageBox.Show("This is the label at value [" + value.ToString() + "]"); } } } Note: The NViewToScale1DTransformation context constructor parameter is deprecated and will be removed in the next version as it is not used as part of the transformation. We hope this helps - let us know if you have any questions.
|
By Kevin Harrison - 4 Years Ago
|
Thanks, but that's not what I asked. I obviously wasn't very clear, sorry. I want to know the coordinates of the axis label so I can put these values into an automated test which will click on that axis label. The transformation code I put in my post gives me the coordinates of any data value within the chart, so this enables our tests to click anywhere within the chart area, but we'd like to extend that to clicking on the axis label.
Is this possible?
Thanks Kevin
|
By Nevron Support - 4 Years Ago
|
Hi Kevin,
Apologies for the delayed response - it took a while to investigate this. Given the current API you cannot get the bounds of the labels in chart view space. You can get the label horizontal and vertical projection along the axis, but it will be difficult to project those to chart view space. Is this a must have functionality?
|
By Kevin Harrison - 4 Years Ago
|
Thanks for looking. I thought that might be the case. We have worked round it for our tests by simulating a click on the axis line as an alternative.
Regards
Kevin
|
|