JFreeChart with selectable domain axis and zoom
Asked Answered
V

1

3

How to have chart like https://www.amcharts.com/demos/line-chart-with-scroll-and-zoom/

I am specifically interested in these functionalities

  1. To be able to select window of domain axis with those 2 selection controlls.
  2. To be able to zoom by selecting portion of domain axis.
  3. To be able to zoom out and see the bigger picture.
  4. To be able to map to range axis (Y) and see the value on that balloon like tool tip at any point (without Marker)

I made initial attempt here Scrollable JFree domain axis and custom marker label with help of trashgod I made domain scrollable.

I am still missing these functionality to be able to use graph effectively.

Vegetal answered 24/5, 2017 at 6:14 Comment(3)
This is not too broad. care to explain why it was classified as too broad ?Vegetal
I am asking for tool, book etc.. recommendation in this question!! Great job ghost closers. Dare to reason your opinion.Vegetal
I chose to answer this question; while it is arguably broad, a useful answer can be adduced by combining several existing approaches.Liberalize
L
7

You'll have to combine several approaches:

  1. Panning controls: Invoke, setDomainPannable(true) to enable panning; in your controls, use panDomainAxes(), as shown in the implementation of mouseDragged(); use the mouse as suggested here.

  2. Zooming: Zooming by dragging on the axis is not supported, but dragging on the plot is supported; drag right to see the selection rectangle. To ensure the mouse wheel only zooms the domain axis when is rolled, invoke setRangeZoomable(false) on the ChartPanel; vice-versa for the range axis.

  3. Zooming out: Drag left to zoom out or use a button handler, as shown here.

  4. Tooltips: Enable tooltips in your chosen ChartFactory. If needed, create a custom XYToolTipGenerator, as shown here.

Liberalize answered 24/5, 2017 at 6:54 Comment(4)
1. Mosts of the problem solved just by adding ` chartPanel.setMouseWheelEnabled(true);` Thanks. How do I make sure it only zooms domain axis when mouse wheel is rolled ?Vegetal
I am using ` this.chartPanel = new ChartPanel(this.chart);` - Don't know if I can override mouse listener event to override custom zoomingVegetal
Sorry, I never tried; look for org.jfree.chart.MouseWheelHandler.Liberalize
Glad it helped; more above on set*Zoomable().Liberalize

© 2022 - 2024 — McMap. All rights reserved.