mousemove and crosshair
Posted: Wed Mar 10, 2010 9:12 pm
Hello,
I have a stock chart showing in one graph price, 50 & 200 day moving averages. I have another chart below it showing the Volume and the 50 day moving average. These charts are combined using the invocation of a CombinedDomainXYPlot
Questions that I have:
* how do you make the vertical cross hair show in both charts when the mouse moves? I've done the chartMouseClicked()/chartMouseMoved() with the following code but no crosshair shows up.
where the setDomainCrosshairValue(xMouseLocation) is as follows:
* as the mouse moves it will be crossing my data values. I would like to get those data values (i believe easy) and display them in the upper left part of the top chart (tough part). How do I have a "floating label"?
Thanks,Jim
I have a stock chart showing in one graph price, 50 & 200 day moving averages. I have another chart below it showing the Volume and the 50 day moving average. These charts are combined using the invocation of a CombinedDomainXYPlot
Questions that I have:
* how do you make the vertical cross hair show in both charts when the mouse moves? I've done the chartMouseClicked()/chartMouseMoved() with the following code but no crosshair shows up.
Code: Select all
ChartEntity entity = event.getEntity();
JFreeChart tmpJFreeChart = event.getChart();
Rectangle2D _plotArea1 = _chartPanel.getChartRenderingInfo().getPlotInfo().getSubplotInfo(0).getDataArea();
Rectangle2D _plotArea2 = _chartPanel.getChartRenderingInfo().getPlotInfo().getSubplotInfo(1).getDataArea();
MouseEvent mouseEvent = event.getTrigger();
Point mouseLocation = mouseEvent.getPoint();
if((_plotArea1.contains(mouseLocation)== true) || (_plotArea2.contains(mouseLocation)==true))
{
Rectangle2D tmpRectangle2D =
(_plotArea1.contains(mouseLocation)== true)
? _plotArea1
: _plotArea2;
int xMouseLocation = mouseEvent.getX();
int yMouseLocation = mouseEvent.getY();
double xValue = tmpRectangle2D.getX();
double width = tmpRectangle2D.getWidth();
_hlcPlot.setDomainCrosshairValue(xMouseLocation);
_vPlot.setDomainCrosshairValue(xMouseLocation);
Code: Select all
ValueAxis domainAxis = theCurrentPlot.getDomainAxis();
Range range = domainAxis.getRange();
double domainCrosshairValue = domainAxis.getLowerBound()
+ (xMouseLocation / 200.0) * range.getLength();
theCurrentPlot.setDomainCrosshairValue(domainCrosshairValue);
Thanks,Jim