Jump to content



Photo

Need help implementing this code

java jfree chart

  • Please log in to reply
8 replies to this topic

#1 thatguyandrew1992

thatguyandrew1992

    Neowinian Senior

  • Tech Issues Solved: 3
  • Joined: 22-January 09

Posted 02 June 2013 - 19:12

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? :(


#2 OP thatguyandrew1992

thatguyandrew1992

    Neowinian Senior

  • Tech Issues Solved: 3
  • Joined: 22-January 09

Posted 03 June 2013 - 04:50

Anyone? Please

#3 firey

firey

    F͎̗͉͎͈͑͡ȉ͎̣̐́ṙ͖̺͕͙̓̌è̤̞͉̟̲͇̍̍̾̓ͥͅy͓̍̎̌̏̒

  • Tech Issues Solved: 6
  • Joined: 30-October 05
  • Location: Ontario, Canada
  • OS: Windows 7
  • Phone: Android (4.1.2)

Posted 03 June 2013 - 12:06

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.

#4 OP thatguyandrew1992

thatguyandrew1992

    Neowinian Senior

  • Tech Issues Solved: 3
  • Joined: 22-January 09

Posted 03 June 2013 - 14:02

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);
  }
}


#5 firey

firey

    F͎̗͉͎͈͑͡ȉ͎̣̐́ṙ͖̺͕͙̓̌è̤̞͉̟̲͇̍̍̾̓ͥͅy͓̍̎̌̏̒

  • Tech Issues Solved: 6
  • Joined: 30-October 05
  • Location: Ontario, Canada
  • OS: Windows 7
  • Phone: Android (4.1.2)

Posted 03 June 2013 - 14:13

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.

#6 OP thatguyandrew1992

thatguyandrew1992

    Neowinian Senior

  • Tech Issues Solved: 3
  • Joined: 22-January 09

Posted 04 June 2013 - 14:31

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

#7 firey

firey

    F͎̗͉͎͈͑͡ȉ͎̣̐́ṙ͖̺͕͙̓̌è̤̞͉̟̲͇̍̍̾̓ͥͅy͓̍̎̌̏̒

  • Tech Issues Solved: 6
  • Joined: 30-October 05
  • Location: Ontario, Canada
  • OS: Windows 7
  • Phone: Android (4.1.2)

Posted 04 June 2013 - 17:01

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?

#8 OP thatguyandrew1992

thatguyandrew1992

    Neowinian Senior

  • Tech Issues Solved: 3
  • Joined: 22-January 09

Posted 05 June 2013 - 18:46

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?

#9 firey

firey

    F͎̗͉͎͈͑͡ȉ͎̣̐́ṙ͖̺͕͙̓̌è̤̞͉̟̲͇̍̍̾̓ͥͅy͓̍̎̌̏̒

  • Tech Issues Solved: 6
  • Joined: 30-October 05
  • Location: Ontario, Canada
  • OS: Windows 7
  • Phone: Android (4.1.2)

Posted 05 June 2013 - 20:47

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.



Click here to login or here to register to remove this ad, it's free!