Suitability of JFreeChart for Realtime Stock Charts

Discussion about JFreeChart related to stockmarket charts.
AlexL

Suitability of JFreeChart for Realtime Stock Charts

Post by AlexL » Thu Sep 04, 2003 1:20 am

Hello,

I am looking to add charts to my java order entry/scanner application that I use, and I was looking into JFreeChart.

I tried the demo on a P4 1.7Ghz 768 MB, and when I launched the "Dynamic Combined Chart" which I thought is close a realtime stock chart. (price , volume plus 1-2 studies), I found that that it was taking 33% of my CPU to draw the graph at it's default size. When I made it bigger, it was taking 65% of CPU.

This made me wonder if I should just stop investigating jfreechart right now because I don't see how it will work if I want to have 10 or more charts on the same screen.

The demo does not even take into account how realtime candlestick charts are drawn. Usually, the last candle is continually updated. It looks like in JFreeChart, this might require recalculating and redrawing the entire chart. For example, a candlestick chart with 1 minute interval, the last candle would be continually updated for one minute, and then shifted over to make room for the next candle. On a very active stock which is trading 10-100 times per second, the candlestick high/low may need to be updated 10-30 times per minutes.

If anyone has any more insight into this please comment. Is the bad performance due to java, or due to jfreechart not designed for realtime charting?

I would really like to use JFreeChart since the API seems to straightforward and has all the necessary features and its open source, but it looks like it can't handle the requirements I'm looking for.

Does anyone know of a commercial java charting package which handles this correctly?

FYI I have a Java order entry/scanner application which I use in conjunction with QCharts for charts. QCharts is a native windows C (C++?) application. I can have 20 1 minute candlesticks charts (price,volume,1 study) displayed on qcharts, and it only takes up about 15% of my CPU in steady state. I think they have optimized their charts to handle many incremental updates per second. Other software I have tried like ESignal seems to perform similarly. I would like to write my own charting application in java so I can integrate better with my order entry/scanner application.

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

Re: Suitability of JFreeChart for Realtime Stock Charts

Post by david.gilbert » Thu Sep 04, 2003 8:07 am

AlexL wrote:Is the bad performance due to java, or due to jfreechart not designed for realtime charting?
It's the latter. When a dataset is updated, JFreeChart redraws the chart entirely...there is no support for incremental redrawing.
David Gilbert
JFreeChart Project Leader

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

AlexL

Post by AlexL » Fri Sep 05, 2003 2:15 am

Hello David,

Is handling realtime charts efficiently something you are considering for jfreecharts?

I think the general problem of adding one additional point is applicable to many domain areas, not just financial. (The bit about updating the last 1 minute candlestick is more specific to financial domain). One other big area I know of is process control, where you are monitoring many statistics of some process, e.g. monitoring all the machines on a printed circuit board manufacturing line. I guess anywhere you charting something as a function of time in realtime.

If the chart is buffered, I would think it would be straightforward to shift the image, and then drawing just the last point or last line segment.
You (or the application developer) would also have to check that the new point is contained within the Y axis; If not, then the entire chart would have to be redrawn with new Y axis. But most of the time (99%), a full redraw would not be necessary.

The X axis would have to be shifted each time a point was added. Possibly, you could just redraw the X axis.
I suppose certain chart options like background images would complicate the process. I guess to handle all the cases, it might get complicated.

Anyway, I'm sure there is a way to do it, possibly with some limitations. But by only having to draw one point instead of N points, the performance is greatly improved. Instead of O(N) operation which gets worse with number of points N, you have a redraw operation which is constant with number of points N but varies based on the window size O(width,height) due to the backstore image which is shifted and blitted. I guess if you have a fullscreen chart with few points, this might actually perform worse!!

I'm looking at commerical packages, and so far none of them list as a feature that they handle realtime updates efficiently, etc. I may have to write test programs to see how they perform.

Have you ever ran your demo/unit tests through a java performance tool like OptimizeIt? Maybe there are some things which can be done to speed it up? Are there some things which could be cached for realtime charts which expect to be updated reapeatedly vs. drawn only once?
In general, I try to optimize for speed vs. memory usage.

-Alex

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

Post by david.gilbert » Fri Sep 05, 2003 10:33 am

AlexL wrote:I guess to handle all the cases, it might get complicated.
I think so.
AlexL wrote:Anyway, I'm sure there is a way to do it, possibly with some limitations.
You'd need to drop anti-aliasing and also focus on integer precision for the Java 2D drawing, so that the newly drawn part of the chart matches up with the retained part from the last draw. Once you do that, though, you start to get tied to the bitmap/screen resolution, and lose some of the advantages of the Graphics2D abstraction. Realtime charting is quite a specialised area...I think specialised enough to justify a library focused on just that. There's an opportunity here for someone to start a project...
AlexL wrote:Have you ever ran your demo/unit tests through a java performance tool like OptimizeIt? Maybe there are some things which can be done to speed it up? Are there some things which could be cached for realtime charts which expect to be updated reapeatedly vs. drawn only once? In general, I try to optimize for speed vs. memory usage.
I haven't. I plan to do some performance testing to ensure that there isn't any code that is overly wasteful. But there are things that add overhead (like the renderer mechanism and the dataset interfaces) that will stay because they add so much flexibility. Here's my rough list of priorities:

1) Flexibility
2) Output quality
3) Ease of use
4) Code readability
5) Performance
6) Memory usage

You could easily improve JFreeChart's performance by trading off 1-4, but those are the things that are important to me. It's not that I want JFreeChart to be slow or a memory hog, but I'm prepared to sacrifice some resources in exchange for those other things. I hope that gives you some idea of my direction...
David Gilbert
JFreeChart Project Leader

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

dmd

real time charting package

Post by dmd » Tue Sep 16, 2003 7:06 pm

There are a ton of commercial apps/applets out there, but there seems to be a whole when it comes to free / open source packages. Maybe there is something out there and I missed it. If not, I would be interested in working with others to see what we could come up with.

davide baroncelli

we too

Post by davide baroncelli » Fri Sep 26, 2003 4:09 pm

My company too is currently evaluating solutions regarding a library that can be integrated to provide real time charting for stock quotes data in a technical analysis application. Given the interest in this kind of issues couldn't it be useful joining our efforts and work jointly to the solution, rather than ending all separately buying licenses of the same commercial libraries?

Guest

Email if interested in working together on real-time chart

Post by Guest » Sun Oct 12, 2003 4:41 pm

Email if interested in working together on real-time java charting package.

esurfer_0001@yahoo.com.no.spam

remove the no.spam after yahoo.com

uls
Posts: 25
Joined: Fri Oct 17, 2003 10:46 am

Post by uls » Fri Oct 17, 2003 10:51 am

i'd be glad to help out, too....
i have a library already, but it's so non-jfreechartish. http://redhorn.sourceforge.net
but it's much faster than jfreechart - but it's not 10% as flexible as jfreechart.

willing to help out with contributing
maybe we can merge some stuff?

kingguppy
Posts: 37
Joined: Mon Apr 07, 2003 9:52 pm
Location: Wuppertal, Germany

Post by kingguppy » Tue Nov 04, 2003 7:06 pm

I've done a fair bit of work optimising JFreeChart to make it more suitable for the real-time charts you're after.

Displaying 10 years of MSFT day data simultaneously as candlesticks, with incoming ticks being added to the final aggregate, and *not* bringing a 2GHz machine to its knees, is pretty much my goal. I'm getting there.

As David said, JFreeChart isn't designed for this sort of thing. But if you're interested in pursuing JFreeChart as an option (you really can't beat the flexibility), look out for the patches I'll be submitting in the next few days.

kingguppy
Posts: 37
Joined: Mon Apr 07, 2003 9:52 pm
Location: Wuppertal, Germany

Post by kingguppy » Mon Dec 01, 2003 2:57 pm

Following up my own message, in case someone's interested in this...

I haven't submitted my patches yet, but I have had quite a bit of success: Rendering 10 years of day data for MSFT on NASDAQ (around 2800 data items) simultaneously as candlesticks, bars, and two lines (in a combination of overlaid and combined plots) takes around 95ms on an Athlon XP 2200+ with 1GB of memory using Linux/XFree86, and without antialiasing. That's not great, but it's fast enough for our purposes, and there's still a bit of room for further optimisation without breaking or excessively complicating JFreeChart's current design. And zooming in now only renders the visible area, so when you're only looking at a couple of hundred items at a time (not unlikely) it's very nippy indeed.

AlexL

Post by AlexL » Thu Dec 04, 2003 5:30 pm

kingguppy,

That sounds like a big improvement. It would be interesting if you posted the before and after times.

Hopefully, your changes can be merged into the CVS.

To be update the chart on every tick, I think I still need to be able to update the last candlestick in the chart. It seems like the only way to approach the performance of QCharts application I use. In my QCharts workspace, I have 30 charts all updating on every tick, and QCharts only uses about 5% CPU on a 2 Ghz P4 1 GB machine.

I have been looking for a good commercial java chart library for *realtime* charts, and I haven't found anything good..

It seems like C#/windows developers have better choices. The Dundas and TeeChart libraries are very fast plus have more support for financial charts.

-Alex

kingguppy
Posts: 37
Joined: Mon Apr 07, 2003 9:52 pm
Location: Wuppertal, Germany

Post by kingguppy » Thu Dec 04, 2003 7:30 pm

Unfortunately there are so many modifications I've made to JFreeChart that my application depends on, it would take a lot of work to run it against the original source for comparison. It might be an order of magnitude faster than it was... but that's just a guess.

I'm submitting the patches one at a time (they're dependent on one another, and David tweaks the patched code before submitting to CVS, and I don't want to get too deep into merge hell). But this looks like it's going to cause a *lot* of waiting, since the last patch I uploaded to the patch manager has been sitting there for a week. Maybe I need to work something out with David to accelerate this process (David, if you're reading this, any suggestions?).

Ideally, updating the last candlestick only (and doing nothing if it's invisible) would of course be what you want to happen. But that's a lot of work, and the current full redraw works well enough for my purposes (a couple of real-time updating charts with indicators and mouse-manipulated drawing tools). I might need to go the next step in optimisation in future, it's certainly something I'd like to work on.

Guest

Post by Guest » Wed Dec 31, 2003 3:44 am

AlexL wrote:kingguppy,


I have been looking for a good commercial java chart library for *realtime* charts, and I haven't found anything good..

It seems like C#/windows developers have better choices. The Dundas and TeeChart libraries are very fast plus have more support for financial charts.

-Alex
Have you tried ILog JViews? I think it will satisfy your requirements.

sphelps1

JSci

Post by sphelps1 » Mon Jan 12, 2004 3:12 pm

JSci provides a graph component that supports real-time updating.

http://sourceforge.net/projects/jsci

It's a bit rough around the edges (the API is not nearly as nice as jfreegraph) but it just about does the job.

I use it in my double-auction (stock-market) simulator

http://www.csc.liv.ac.uk/~sphelps/jasa

JOhn Coleman
Posts: 3
Joined: Fri Mar 19, 2004 7:59 pm

Re: Suitability of JFreeChart for Realtime Stock Charts

Post by JOhn Coleman » Fri Mar 19, 2004 8:12 pm

I use Jfree for 1 minute realtime charting of 7 markets at a time. I have no problems with performance at all and even have a horizontal line giving the last price in realtime.

My charts are in a tab pane so only 1 visible at a time and I keep the size small. It's the painting that consumes CPU. Upgrade the CPU to run many big charts visible at a time.

Processor is 1GHz Athlon, 512MB ram BTW.

All works fine.

Why not write some AI to alert the user to significant price events and then paint the chart at that time?


John

Locked