I suppose that it is very simple question. I am sorry.
Chart - ScatterPlot
How to get point under the mouse.
For example:
X axis- from 0 to 1.
Y axis- from 10 to 20
If i click in the center of the chart, i must achieve point (0.5;15)
Is there any function that returns the real point of chart?
Or i must operate X and Y from the mouse event? In this case. How i can get the width of the Y axis legend? And the height of Title of chart?
Thank you.
How to get point of the chart under the mouse?
Re: How to get point of the chart under the mouse?
In my code I use the following
Code: Select all
Rectangle2D dataArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea();
Point2D p = chartPanel.translateScreenToJava2D(pt);
double chartX = xyplot.getDomainAxis().java2DToValue(p.getX(), dataArea, xyplot.getDomainAxisEdge());
double chartY = xyplot.getRangeAxis().java2DToValue(p.getY(), dataArea, xyplot.getRangeAxisEdge());
Re: How to get point of the chart under the mouse?
Hi skunk,
Sorry for the stupid question but what is 'pt' here? and how do we get it??
Sorry for the stupid question but what is 'pt' here? and how do we get it??
Re: How to get point of the chart under the mouse?
pt is an instance of java.awt.Point in screen coordinates. Call getPoint() on the MouseEvent object that is passed as an argument to all mouse event handlers.
Re: How to get point of the chart under the mouse?
Hi Skunk,
Thanks a lot. You are great.
Sorry for asking so many question, but i have one more question here,
i m creating data like-
TimeSeries localTimeSeries1 = new TimeSeries("Series 1");
localTimeSeries1.add(new Month(1, 2002), 500.19999999999999D);
but, mouse click on plot giving me x and y both value in double ( as you suggested.)
now i want to add this point to timeseries as-
double chartX = xy.getDomainAxis().java2DToValue(p.getX(), dataArea, xy.getDomainAxisEdge());
double chartY = xy.getRangeAxis().java2DToValue(p.getY(), dataArea, xy.getRangeAxisEdge());
localTimeSeries1.add(chartX, chartY);
can you guide me how to convert chartX value in correct format like new Month(1,2002) does to add new point to series.
Thanking You.
warm regards,
Vimal
Thanks a lot. You are great.
Sorry for asking so many question, but i have one more question here,
i m creating data like-
TimeSeries localTimeSeries1 = new TimeSeries("Series 1");
localTimeSeries1.add(new Month(1, 2002), 500.19999999999999D);
but, mouse click on plot giving me x and y both value in double ( as you suggested.)
now i want to add this point to timeseries as-
double chartX = xy.getDomainAxis().java2DToValue(p.getX(), dataArea, xy.getDomainAxisEdge());
double chartY = xy.getRangeAxis().java2DToValue(p.getY(), dataArea, xy.getRangeAxisEdge());
localTimeSeries1.add(chartX, chartY);
can you guide me how to convert chartX value in correct format like new Month(1,2002) does to add new point to series.
Thanking You.
warm regards,
Vimal
Re: How to get point of the chart under the mouse?
Code: Select all
Date date = new Date((long)chartX);
Re: How to get point of the chart under the mouse?
Thanks a lot skunk !!