mousemove and crosshair

Discussion about JFreeChart related to stockmarket charts.
Locked
jim_athome
Posts: 4
Joined: Mon May 26, 2008 9:24 pm

mousemove and crosshair

Post by jim_athome » 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.

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);			
where the setDomainCrosshairValue(xMouseLocation) is as follows:

Code: Select all

        ValueAxis domainAxis = theCurrentPlot.getDomainAxis();
        Range range = domainAxis.getRange();
        double domainCrosshairValue = domainAxis.getLowerBound()
                   + (xMouseLocation / 200.0) * range.getLength();
    	theCurrentPlot.setDomainCrosshairValue(domainCrosshairValue);
* 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

jim_athome
Posts: 4
Joined: Mon May 26, 2008 9:24 pm

Re: mousemove and crosshair

Post by jim_athome » Thu Mar 11, 2010 7:38 pm

Hello,

Found the answer my own question after doing some research of the source code that came w/ the Developer's Guide. I have the first question answered and the 2nd question should be just as easy.

Jim

Locked