Absolute to Relative Chart Coordinates
|
Logged in as: Guest
|
|
Users viewing this topic:
none
|
|
Login | |
|
Absolute to Relative Chart Coordinates - 4/2/2007 11:32:26 AM
|
|
|
rkitson
Posts: 13
Joined: 3/5/2007
Status: offline
|
I have a number of Annotations on a chart, and because there is currently no feature to allow the user to move these intecatively on the chart I'm trying to implement something crude and simple. I'm using the Chart click event to first capture the coordinated via e.X and e.Y of where the user wants to move the annotation to (store off in a session vaiable), and then a callback event when the user clicks on an annotation to move. I'm trying to convert the e.X and e.Y absolute coordinates to chart relative coordinates so that I can set the AnchorOffsetX and AnchorOffsetY of the selected Annotation. I've tried instantiating ChartGraphics to get at the .GetRelativePoint method, but there are no public constructors on this class to be able to instantiate it. How else can I get this absolute to relative conversion? Is there an easier way to do a simple user interactive move of the annotation? Has Dundas any plans to provide interactive annotation movement in upcoming releases? Thanks.
|
|
|
|
RE: Absolute to Relative Chart Coordinates - 4/4/2007 11:16:21 AM
|
|
|
Veslav
Posts: 1137
Joined: 10/6/2006
Status: offline
|
You do not need to use ChartGraphics object. Chart control provides such functionality directly. See PixelPositionToValue and ValueToPixelPosition methods of Axis. Sample code: ann = TextAnnotation protected void Chart1_Click(object sender, ImageClickEventArgs e) { double X = chart1.ChartAreas[0].AxisX.PixelPositionToValue(e.X); double Y = chart1.ChartAreas[0].AxisY.PixelPositionToValue(e.Y); ann.X = X; ann.Y = Y; }
|
|
|
|
RE: Absolute to Relative Chart Coordinates - 4/4/2007 12:01:37 PM
|
|
|
rkitson
Posts: 13
Joined: 3/5/2007
Status: offline
|
Thanks for the reply, I tried using the code double X = chart1.ChartAreas[0].AxisX.PixelPositionToValue(e.X); double Y = chart1.ChartAreas[0].AxisY.PixelPositionToValue(e.Y); but the X and Y values get set to NaN. I stepped through the code and e.X and e.Y are set to some values, the chart1 has a couple of series with data points, the chartarea[0] has a height and width etc etc Any reason the method would convert e.X = 180 and e.Y=380 (a couple of actual values from when I clicked the chart and stepped through) to NaN ??
|
|
|
|
RE: Absolute to Relative Chart Coordinates - 4/4/2007 1:02:29 PM
|
|
|
Veslav
Posts: 1137
Joined: 10/6/2006
Status: offline
|
You have to use this code inside of Click event. Another way is to call "repaint" of Chart control before using PixelPositionToValue: chart1.SaveAsImage(Stream.Null);
|
|
|
|
RE: Absolute to Relative Chart Coordinates - 4/4/2007 5:00:15 PM
|
|
|
rkitson
Posts: 13
Joined: 3/5/2007
Status: offline
|
OK, but, I do have the 2 lines of code within the Click event... protected void workspaceChart_Click(object sender, ImageClickEventArgs e) { HitTestResult hitTestResult = workspaceChart.HitTest(e.X, e.Y); if (hitTestResult != null) { double X = workspaceChart.ChartAreas[0].AxisX.PixelPositionToValu(e.X); double Y = workspaceChart.ChartAreas[0].AxisY.PixelPositionToValu(e.Y); \\some other code here } } and it gives me a NaN back. Could it have something to do with the fact that I have the Context menu UI turned on and I have Zoom and Scrolling enabled ? If not then I guess I'll try and create a simple test page and see if the method works.
|
|
|
|
RE: Absolute to Relative Chart Coordinates - 4/5/2007 12:05:05 PM
|
|
|
Veslav
Posts: 1137
Joined: 10/6/2006
Status: offline
|
In some cases we have to call ReCalc method for ChartAreas. For Chart ASP.NET control this case is. void Chart1_Click(object sender, ImageClickEventArgs e) { HitTestResult hitTestResult = Chart1.HitTest(e.X, e.Y); if (hitTestResult != null) { Chart1.ChartAreas[0].ReCalc(); double X = Chart1.ChartAreas[0].AxisX.PixelPositionToValue(e.X); double Y = Chart1.ChartAreas[0].AxisY.PixelPositionToValue(e.Y); } }
|
|
|
|
RE: Absolute to Relative Chart Coordinates - 4/6/2007 11:16:13 AM
|
|
|
rkitson
Posts: 13
Joined: 3/5/2007
Status: offline
|
Works now...Thanks a lot.
|
|
|
|
New Messages |
No New Messages |
Hot Topic w/ New Messages |
Hot Topic w/o New Messages |
Locked w/ New Messages |
Locked w/o New Messages |
|
Post New Thread
Reply to Message
Post New Poll
Submit Vote
Delete My Own Post
Delete My Own Thread
Rate Posts |
|
|