Andrei Sh
Andrei Sh

Reputation: 113

How to set jfreechart auto range to the chosen values?

I draw a two-dimensional graph in which I set ranges for both axes by certain values. But when I select the graph menu 'auto range > both axes' I get other ranges (maybe obviously).

I want to set auto range into my defined range, with my values. How can I do this?

XYPlot xyPlot = chart.getXYPlot();
NumberAxis domainAxis = (NumberAxis) xyPlot.getDomainAxis();

domainAxis.setRange(minXChart, maxXChart);
domainAxis.setTickUnit(new NumberTickUnit(xTickInterval));

rangeAxis.setRange(minYChart, maxYChart);
rangeAxis.setTickUnit(new NumberTickUnit(yTickInterval));
  1. graph with defined range (i want exactly the same but with auto range)

  2. graph with auto range (bad looking)

Upvotes: 0

Views: 1609

Answers (1)

trashgod
trashgod

Reputation: 205775

Some possible approaches:

  • Override the ChartPanel method restoreAutoBounds(), as shown here, to establish your preferred bounds.

  • Remove the feature from the context menu using the zoom parameter of a suitable ChartPanel constructor and handle the action with your own control, as shown here for Auto Zoom.

Upvotes: 1

Related Questions