How to remove auto axis stretch?

I am using JFreeChart 1.0.14 . The labels of my axis are stretched very strange if the plot is too small / large. I want to disable this behavior and want the label labels to always print with the same width: height ratio.

stretched

Here is the SSCCE:

 import java.awt.BorderLayout; import javax.swing.JFrame; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.chart.plot.PlotOrientation; import org.jfree.data.xy.XYSeries; import org.jfree.data.xy.XYSeriesCollection; public class Main { public static void main(String[] args) { JFrame frame = new JFrame(); frame.setLayout(new BorderLayout()); XYSeries series = new XYSeries("series a"); for (int i = 0; i < 100; i++) series.add(i, Math.sin(i / 2.0) * Math.cos(i / (2.0 + Math.random()))); XYSeriesCollection dataset = new XYSeriesCollection(series); JFreeChart chart = ChartFactory.createXYLineChart("", "x-axis", "y-axis", dataset, PlotOrientation.VERTICAL, false, false, false); ChartPanel panel = new ChartPanel(chart); frame.add(panel, BorderLayout.CENTER); frame.setSize(400, 200); frame.setLocationRelativeTo(null); frame.setVisible(true); } } 

It produces output labeled OK . When I change the frame size in any direction by a certain amount, the cue marks (and cue marks) begin to distort (as can be seen from the two frames marked with a stretched sign). And their "stretch ratio" is synchronized.

I can’t figure out how to disable this β€œfunction” and always show axis labels with a fixed ratio of width and height. Do you know how to do this?

+4
source share
1 answer

This is an example of scaling .

You need to set the maximum and minimum thread height and width on the ChartPanel . You can install them once:

 ChartPanel panel = new ChartPanel(chart); panel.setMaximumDrawHeight(1000); panel.setMaximumDrawWidth(1000); panel.setMinimumDrawWidth(10); panel.setMinimumDrawHeight(10); 

using some suitable values ​​or add a ComponentListener :

  frame.addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { panel.setMaximumDrawHeight(e.getComponent().getHeight()); panel.setMaximumDrawWidth(e.getComponent().getWidth()); panel.setMinimumDrawWidth(e.getComponent().getWidth()); panel.setMinimumDrawHeight(e.getComponent().getHeight()); } }); 
+10
source

All Articles