Add Drawing Figure Capability To JFreeChart

Discussion about JFreeChart related to stockmarket charts.
Locked
yccheok
Posts: 48
Joined: Mon Feb 16, 2009 4:58 am

Add Drawing Figure Capability To JFreeChart

Post by yccheok » Mon Feb 16, 2009 6:09 am

Hello all,

I had been applied JFreeChart into an open source stock market software : jstock.sourceforge.net. Currently, it gets pretty good feedback from the users.

Recently, I get some additional request from the users, particular for those users who prefer to perform some technical analysis on the chart itself.

Hence, I was thinking to add some drawing capability into JFreeChart. User is able to draw a text, draw a rectangle, draw a circle, resize a figure... on the chart.

Instead of developing from scratch, I plan to integrate a cool figure drawing library sourceforge.net/projects/jhotdraw together with JFreeChart

I was wondering had anyone here do a similar task before. Mine to share some of your experience?

Thanks!
Cheok

RoyW
Posts: 93
Joined: Wed Apr 23, 2008 7:42 pm
Contact:

Post by RoyW » Tue Feb 24, 2009 7:34 pm

I implemented tecnical tools, trendline, trendchannel, fibonacii fan lines, fibonacii retracement lines, Text with arrow, Speedlines, Pitchfork.

This was done by creating classes that implement the XYAnnotation interface and then simply do the drawing using Java2D.

Interactivity was achieved by detecting mousemove/drag events and directly calling the draw() method of the annotataion. When the user clicked the final point the annotation was added to the chart just like all other annotations.
The answer does not come from thinking outside the box, rather the answer comes from realizing the truth; There is no Box. my js site

yccheok
Posts: 48
Joined: Mon Feb 16, 2009 4:58 am

Re: Add Drawing Figure Capability To JFreeChart

Post by yccheok » Mon Mar 02, 2009 10:26 pm

Very cool. Do you have any plan to open source your work? If yes, I would like to integrate your work into mine ;)

Celso
Posts: 10
Joined: Mon Feb 16, 2009 6:39 pm

Re: Add Drawing Figure Capability To JFreeChart

Post by Celso » Tue Mar 03, 2009 1:55 am

Hi RoyW,

could you post a piece of your code?
I can draw trendlines, but i can´t move or edit with mouse!

Could you help me?

Thanks a lot,
Celso

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: Add Drawing Figure Capability To JFreeChart

Post by david.gilbert » Tue Mar 03, 2009 11:07 am

I don't have much to add to this discussion right now, but I thought that I'd mention that I'm using JXLayer at the moment to overlay crosshairs on charts for a client project. JXLayer is, I think, a pretty good solution for adding a layer (including interactive stuff) above a chart. So maybe it is worth looking at...
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

RoyW
Posts: 93
Joined: Wed Apr 23, 2008 7:42 pm
Contact:

Re: Add Drawing Figure Capability To JFreeChart

Post by RoyW » Wed Mar 04, 2009 3:13 pm

The code I have is very specific to the project I am working on. I will try and seperate code just for charting to see if I can come up with a single example. The problem is I created my own chart panel (InteractiveChartPanel) that extended JComponent and was specific to the financial charts I was creating(Always horizontal, always XYChart, range always on right). I will try to provide a cut down version to show the direction I was headed but I cannot say when I will be able to get to this.

I would take a look at some of the classes in JFreeChart that implement the XYAnnotation. That is what I did to produce my technical indicators.

I also provided a method "containsPoint(Point2D point)" in my annotations that checked if a point was "near" the annotation
(for example for a trend line it calculated the distance of the point from the line)

Code: Select all

      //Is the point within 4 pixels of the line
      return Line2D.ptLineDist(x1, y1, x2, y2, point.getX(), point.getY()) < 4.0);
That way you can provide a context menu for the annotations.


David, I have seen JXLayer before. I have not had time to look at it in detail but I am very impressed with the demos.
I added my interactivity by detecting the first mouse click then capturing the current chart in a buffered image. As the mouse moved I would use the buffered image to "clear" the drawing area then draw the annotation over the image. This allowed me to rubber band the annotation so the user can see it draw as they are moving the mouse. I will try to include that in the simple example (time permitting).
The answer does not come from thinking outside the box, rather the answer comes from realizing the truth; There is no Box. my js site

Locked