简体   繁体   中英

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)

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM