Dundas Data Visualization SupportYour Partner In Creating Digital Dashboard Solutions
Phone: 416.467.9100  |  support@dundas.com Dundas Support Home  |  Dundas Data Visualization  |  Contact Us

Absolute to Relative Chart Coordinates

 
Logged in as: Guest
Users viewing this topic: none
  Printable Version
All Forums >> [Dundas Chart] >> [Support] >> Dundas Chart for ASP.NET >> Absolute to Relative Chart Coordinates Page: [1]
Login
Message << Older Topic   Newer Topic >>
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.
Post #: 1
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;
    }

(in reply to rkitson)
Post #: 2
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 ??

(in reply to Veslav)
Post #: 3
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);

(in reply to rkitson)
Post #: 4
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.

(in reply to Veslav)
Post #: 5
RE: Absolute to Relative Chart Coordinates - 4/4/2007 5:29:52 PM   
rkitson

 

Posts: 13
Joined: 3/5/2007
Status: offline
So I tried creating a simple page and it still brings back NaN.......see xml attachement for chart and below is what I put in the codebehind....


protected void Page_Load(object sender, EventArgs e)
{
Chart1.Series[0].Points.AddXY(5, 5);
Chart1.Series[0].Points.AddXY(10, 10);
Chart1.Series[0].Points.AddXY(15, 15);
Chart1.Series[0].Points.AddXY(20, 20);
Chart1.Series[0].Points.AddXY(25, 25);
Chart1.Click +=
new ImageClickEventHandler(Chart1_Click);
}
void Chart1_Click(object sender, ImageClickEventArgs e)
{
HitTestResult hitTestResult = Chart1.HitTest(e.X, e.Y);
if (hitTestResult != null)
{
double X = Chart1.ChartAreas[0].AxisX.PixelPositionToValue(e.X);
double Y = Chart1.ChartAreas[0].AxisY.PixelPositionToValue(e.Y);
}
}


Attachment (1)

(in reply to rkitson)
Post #: 6
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);
        }
    }

(in reply to rkitson)
Post #: 7
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.

(in reply to Veslav)
Post #: 8
Page:   [1]
All Forums >> [Dundas Chart] >> [Support] >> Dundas Chart for ASP.NET >> Absolute to Relative Chart Coordinates Page: [1]
Jump to:





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