|
Scrolling Chart access to Screen Coordinates |
Posted by Aaron Dow on Aug-24-2007 07:00 |
|
I am trying to create a scrolling chart where the user can mouse over the chart and have a dot track the values at different points on the chart.
However when I use some of the calculations listed on this site, I get huge numbers that are outside my data collection.
In the example I am working with, I have about 55,000 points and about 10 different line elements. So, there is quite a bit of data.
Here is where I am at:
private void cvChart_MouseMove(object sender, MouseEventArgs e)
{
//Quoted version that should work
//xcoor = (xPixel - plotAreaLeft) / plotAreaWidth *
(chtDist.xAxis().getMaxValue() - chtDist.xAxis().getMinValue())
//ycoor = (plotAreaBottom - yPixel) / plotAreaHeight *
(chtDist.yAxis().getMaxValue() - chtDist.yAxis().getMinValue())
For xcoor, I am gettin a number over 1.8 million
1. What exactly is the plotAreaLeft?
c.setPlotArea(52, 85, iChartWidth, iChartHeight, 0xffffff, -1, -1, 0xeaeaea, 0xeaeaea);
I am assuming that it is 52.
2. What is xPixel. I am assuming it is the e.X
3. The getMinValue() and getMaxValue() return very large numbers.
I know that I need to include scaling calculations in this, but the only example I found was for vb and worked with ScaleX, etc. I wasn't easily able to find the translated method for C#.
Thanks, for any help! |
Re: Scrolling Chart access to Screen Coordinates |
Posted by Peter Kwan on Aug-24-2007 19:04 |
|
Hi Aaron,
Recently, we have even discovered a method that does not even need plotAreaLeft and plotAreaWidth. It turns out these parameters can be retrieved using the ChartDirector API and so do not need to be provided. (The ChartDierctor API is so flexible sometimes even the developers of ChartDirector have not exhausted all possible usage.)
The code we now suggest is (in C#)
double xcoor = (e.X - c.getXCoor(c.xAxis().getMinValue())) / (c.getXCoor(c.xAxis().getMaxValue()) - c.getXCoor(c.xAxis().getMinValue())) * (c.xAxis().getMaxValue() - c.xAxis().getMinValue()) + c.xAxis().getMinValue()
If you want the code to be easier to understand, you may break it down like:
//axis metrics
double xAxisMin = c.xAxis().getMinValue();
double xAxisMax = c.xAxis().getMaxValue();
int pixelAtXMin = c.getXCoor(xAxisMin);
int pixelAtXMax = c.getXCoor(xAxisMax);
//linear interpolation
double xValue = (e.X - pixelAtXMin) / (pixelAtXMax - pixelAtXMin) * (xAxisMax - xAxisMin) + xAxisMin;
Note that even in your original code, there should be a "+ chtDist.xAxis().getMinValue()" at the end (unless you can assume the min value is always 0).
If you get a large number as the xValue (like many millions), it does not necessarily means the xValue is incorrect. May be you data are really using millions as the x-coordinates. If you are using DateTime as the x-coordinate, note that in order to use numeric computations, the DateTime must be converted to a numeric represenation (as you cannot apply things like multiplication and division to DateTime), and in ChartDirector is it "seconds elapsed since Jan 1, 0001 00:00:00". It is entirely possible many millions of seconds have elapsed since the above date.
If you are in fact using DateTime as the x-coordinate system, you may translate the "seconds elapsed" to DateTime using:
DateTime xDateTime = Chart.CTime(xValue);
Hope this can help.
Regards
Peter Kwan |
Re: Scrolling Chart access to Screen Coordinates |
Posted by Aaron Dow on Aug-28-2007 23:02 |
|
I understand DateTime objects. My issue was I needed the index into the DataSet so I can show the user the values at a given point in time. By getting the X coordinate in the long DateTime, I then have to cycle through my local collection looking for that datetime. Then the problem occurs that there can be readings within seconds of each other or days apart. The process of looking back through the data to find that DateTime was too slow.
I just was looking for an easy way to grab the DataSet in the graph. |
Re: Scrolling Chart access to Screen Coordinates |
Posted by Aaron Dow on Aug-28-2007 23:03 |
|
I understand DateTime objects. My issue was I needed the index into the DataSet so I can show the user the values at a given point in time. By getting the X coordinate in the long DateTime, I then have to cycle through my local collection looking for that datetime. Then the problem occurs that there can be readings within seconds of each other or days apart. The process of looking back through the data to find that DateTime was too slow.
I just was looking for an easy way to grab the DataSet in the graph. |
Re: Scrolling Chart access to Screen Coordinates |
Posted by Peter Kwan on Aug-29-2007 05:23 |
|
Hi Aaron,
Actually, cycle through my local collection looking for that datetime should be quite fast if binary searching is used. It should only take around 1 microseconds or at the order of magnitude. Even if your data are non-regularly spaced (sometimes seconds apart and sometimes days apart), the speed of binary searching will not be affected.
Hope this can help.
Regards
Peter Kwan |
Re: Scrolling Chart access to Screen Coordinates |
Posted by Alden on Feb-18-2011 22:16 |
|
Hi There,
I've tried getting the axis coordinates on a MouseMoved event in Java. I'm using a
financeChart object, but can't seem to have any joy. The XYChart object has methods to
get the coordinates, but i get a classcast exception when trying to get the coordinates
from a financeChart object:
"java.lang.ClassCastException: ChartDirector.FinanceChart cannot be cast to
ChartDirector.XYChart"
Is there any way to get the x and y axis values from a finance chart for mousemoved
and/or hotspot events?
Thanks,
Alden |
Re: Scrolling Chart access to Screen Coordinates |
Posted by Alden on Feb-19-2011 01:23 |
|
Sorry, the following thread explains it:
http://www.chartdir.com/forum/download_thread.php?
bn=chartdir_support&pattern=get+axis+values&thread=1270628136#N1270709207 |
|