0

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)

Andrei Sh
  • 113
  • 1
  • 11

1 Answers1

1

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.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • I've found solution only to part of my question associated with wrong autorange: '// fixing x axis NumberAxis domainAxis = (NumberAxis) xyPlot.getDomainAxis(); domainAxis.setLowerMargin(0); domainAxis.setUpperMargin(0); // fixing y axis NumberAxis rangeAxis = (NumberAxis) xyPlot.getRangeAxis(); rangeAxis.setAutoRangeIncludesZero(false);' Problem with lower border y axis was that all my data points are positive values. But still I don't know how to set autorange to the chosen values. – Andrei Sh Sep 26 '16 at 02:17
  • Code in comments is incomplete and hard to read; please edit your question to include a [mcve] that shows your revised approach. – trashgod Sep 26 '16 at 03:22