• 0

Need help implementing this code


Question

Hey all,

I am making a chart program with jfree chart. If you go to this forum ( http://www.jfree.org...to+mouse#p82001 ) a user wants to create a dot that follows a mouse along a plotted line. I also want to do this, or something similar.

Another user posted some of his code which accomplishes this. However I can't figure out how to implement it. The post is really old and users arent responding to it anymore.

What the user said:

I was able to implement the feature "having small color ball along graph line while mouse move"

We are using binary search to located the nearest point.

Take a look if you are interested ;

http://jstock.cvs.so...1.3&view=markup

http://jstock.cvs.so...1.8&view=markup

The code in CrossHairUI.java is the relevant code I believe. Idk how to use it.

Any ideas? :(

Link to comment
Share on other sites

8 answers to this question

Recommended Posts

  • 0

looks like you just add in the .java file into you project. Create a new instance of the object, and I assume it will just work.

Link to comment
Share on other sites

  • 0

Maybe im missing the obvious, is this what you meant?


import org.jfree.chart.*;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.xy.*;
import org.yccheok.jstock.charting.CrossHairUI;
public class xyLine2{
public static void main(String arg[]){

CrossHairUI cross = new CrossHairUI();

XYSeries series = new XYSeries("Average Weight");
series.add(20.0, 20.0);
series.add(40.0, 25.0);
series.add(55.0, 50.0);
series.add(70.0, 65.0);
XYDataset xyDataset = new XYSeriesCollection(series);
JFreeChart chart = ChartFactory.createXYLineChart
("XYLine Chart using JFreeChart", "Age", "Weight",
xyDataset, PlotOrientation.VERTICAL, true, true, false);
ChartFrame frame1=new ChartFrame("XYLine Chart",chart);
frame1.setVisible(true);
frame1.setSize(1000,800);
}
}
[/CODE]

Link to comment
Share on other sites

  • 0

That's what I would think. Could also try making the CrossHairUI at the end of all the objects. Also, does the crosshair provide the ability to interact with the jfree chart? It looks like it includes references to it.

Link to comment
Share on other sites

  • 0

My guess is that the mouse events aren't being caught by the class. Can you add break points in the code to see if it is running any of it?

Link to comment
Share on other sites

  • 0

I will try to add that later. Just curious, why would making an object of the CrossHair work? I don't think it would work if I just create an object. Don't I need to call that code?

Link to comment
Share on other sites

  • 0

I will try to add that later. Just curious, why would making an object of the CrossHair work? I don't think it would work if I just create an object. Don't I need to call that code?

I am not entirely sure about how java works, but I would have thought the override functions would have been called automatically. The only two public options are get and set point which the code is supposed to do.

It's possible though that that code is not 100% complete, you may need to put your char tcreation code in the constructor of that cross hair object and have it create the chart for you.

Link to comment
Share on other sites

This topic is now closed to further replies.