9 posts in this topic

Posted

Hey all,
I am making a chart program with jfree chart. If you go to this forum ( [url="http://www.jfree.org/forum/viewtopic.php?f=3&t=29379&p=82001&hilit=nearest+point+to+mouse#p82001"]http://www.jfree.org...to+mouse#p82001[/url] ) 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:
[quote]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 ;

[url="http://jstock.cvs.sourceforge.net/viewvc/jstock/jstock/src/org/yccheok/jstock/charting/CrossHairUI.java?revision=1.3&view=markup"]http://jstock.cvs.so...1.3&view=markup[/url]
[url="http://jstock.cvs.sourceforge.net/viewvc/jstock/jstock/src/org/yccheok/jstock/gui/ChartJDialog.java?revision=1.8&view=markup"]http://jstock.cvs.so...1.8&view=markup[/url][/quote]

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

Any ideas? :(

Share this post


Link to post
Share on other sites

Posted

Anyone? Please

Share this post


Link to post
Share on other sites

Posted

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.

Share this post


Link to post
Share on other sites

Posted

Maybe im missing the obvious, is this what you meant?
[CODE]
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]

Share this post


Link to post
Share on other sites

Posted

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.

Share this post


Link to post
Share on other sites

Posted

Putting it at the end didn't work. :( I think it can interact with the jfree chart. This code is confusing me! :/

Share this post


Link to post
Share on other sites

Posted

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?

Share this post


Link to post
Share on other sites

Posted

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?

Share this post


Link to post
Share on other sites

Posted

[quote name='thatguyandrew1992' timestamp='1370458009' post='595738924']
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?
[/quote]


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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.