jfreechart
jfreechart copied to clipboard
Crosshairs broken in v1.5.4
Going from release v1.5.3 to v1.5.4 crosshair functionality stopped working. Clicking on charts no longer updates the crosshair.
To reproduce:
Setup
- Find demos with crosshairs: https://github.com/jfree/jfree-demos/search?q=crosshair Note: jfree-demos currently lists JfreeChart v1.5.3 in the README but doesn't have a v1.5.3 release tag. It's up to v1.5.2.
-
git clone https://github.com/jfree/jfree-demos.git
-
cd jfree-demos
-
git checkout -b crosshair-test v2.0
Test v1.5.2
-
mvn clean package
-
java -cp target/org.jfree.demos-2.0-jar-with-dependencies.jar org.jfree.chart.demo2.TimeSeriesChartDemo1
- Observe clicking the chart updates the crosshair.
- Close the app.
Test v1.5.3
- Set the POM jfreechart dependency to v1.5.3
- Repeat build and launch steps.
- Observe clicking the chart updates the crosshair.
- Close the app.
Test v1.5.4
- Set the POM jfreechart dependency to v1.5.4
- Repeat build and launch steps.
- Observe the crosshair doesn't update. If you resize the window (trigger a re-draw) the crosshair updates to the last clicked location.
I suspect it's related to a v1.5.4 contribution.
For reference, I can reproduce the anomaly in TimeSeriesChartDemo1
and similar examples that make the crosshairs visible on the plot, but not in examples that use CrosshairOverlay
, seen here and here.
At first glance it seems to be caused by the removal of this line in ChartPanel.java
between v1.5.3 and v1.5.4:

Thanks for having taken a look!
Yes, thank you. After restoring the call to setNotify()
, I can no longer reproduce the anomaly. Related discussion may be found here and here.
At first glance it seems to be caused by the removal of this line in
ChartPanel.java
between v1.5.3 and v1.5.4:![]()
I know exactly when this was introduced, see https://github.com/jfree/jfreechart/pull/233#discussion_r655296139. The problem now is that large charts are re-rendered every time when a user clicks with the mouse. This leads to very laggy behavior when selecting chart elements, though the selection itself is rendered using an ChartOverlay which is very fast.
I've created an alternative solution that prevents charts without corsshairs to redraw on every mouse click, see #362.
For this I have reused - what seems - an older implementation JFreeChart#handleClick(...) that exactly seems to solve this issue. This public method isn't called anywhere else anymore within the library.