The charts on Yahoo and Google finance have a small text somewhere that shows
the data for the x-coordinate under the mouse, as you move the mouse. You can
see the Yahoo implementation of this at http://finance.yahoo.com/echarts?s=AAPL ... =undefined;
I want to do the same thing in JFreeChart, or anything similar that tracks the
mouse dynamically and updates a text showing the data at the mouse-position.
I have a working mouseMoved() method on ChartPanel that follows the mouse,
and gets the right data, and prints it to system.out. That works ok.
Now how am I to display the text on the chart and update it dynamically?
I tried tooltips but that didn't work (see post a day or two ago). Summary:
Tooltips require holding the mouse over the exact tiny dot or OHLC bar or whatever
on the chart, and it's too small for the user to hit; and one can't make the hit-algorithm work
more approximately, because it's buried in the Java API.
I then tried annotations. Unfortunately I noticed this in the manual:
... there is no event notication mechanism (yet) for annotations. If you modify an anno-
tation, you will need to manually trigger a redraw of the chart (for example, by calling
chart.setNotify(true));
That would refresh the entire chart, not just the text in the annotation box, right?
And I am thinking it would be way too slow to track mouse-motion well. Agree?
So how can one do this in JFreechart?
tia/jwg
Dynamic update of text on a chart: impossible?
-
- Posts: 1634
- Joined: Sat Feb 17, 2007 1:51 pm
Re: Dynamic update of text on a chart: impossible?
With JfreeCHart 1.0.13, an event handling mechanism for annotations should be supported.
Regarding the drawing speed, you might be right.
Have you looked at the Overlay stuff in the package org.jfree.chart.panel? That looks like as if it could be of use.
Ifg you do not need to show the tool tip on the chart: have you tried to use a ChartMouseListener? if the ChartMouseMoves, you could check whether the ChartEntity of the chartMosueEvent is of any use. If not, expand the search around the coordinates of the original mouse event.
Regarding the drawing speed, you might be right.
Have you looked at the Overlay stuff in the package org.jfree.chart.panel? That looks like as if it could be of use.
Ifg you do not need to show the tool tip on the chart: have you tried to use a ChartMouseListener? if the ChartMouseMoves, you could check whether the ChartEntity of the chartMosueEvent is of any use. If not, expand the search around the coordinates of the original mouse event.
Re: Dynamic update of text on a chart: impossible?
Thanks paradoxoff.
I never heard of the overlay stuff; I'll have a look.
I'm using the ChartMouse mouse-motion listener. Works fine.
I have a DateAxis, and I don't need to identify the entity I'm over,
I just need the date the mouse is over (the x-coord). Then I go
back to my application data and generate the text I need.
That all works ok.
The trouble is: no way to display the text, neither as a balloon
near the spot in question nor in a dedicated area in the corner
of the screen or anything else, where I can update it efficiently.
Everything wants to generate events to refresh the whole chart.
I have solved the problem for now by updating the title bar of the
window. This goes outside the Chart entirely and is just a windows
call. Works fine, but kind of a sad solution.
I'll check the overlay stuff.
jwg
I never heard of the overlay stuff; I'll have a look.
I'm using the ChartMouse mouse-motion listener. Works fine.
I have a DateAxis, and I don't need to identify the entity I'm over,
I just need the date the mouse is over (the x-coord). Then I go
back to my application data and generate the text I need.
That all works ok.
The trouble is: no way to display the text, neither as a balloon
near the spot in question nor in a dedicated area in the corner
of the screen or anything else, where I can update it efficiently.
Everything wants to generate events to refresh the whole chart.
I have solved the problem for now by updating the title bar of the
window. This goes outside the Chart entirely and is just a windows
call. Works fine, but kind of a sad solution.
I'll check the overlay stuff.
jwg