How to set same scale for domain and range axes JFreeChart?

Sans legend setting the preferred size of the ChartPanel works pretty well.

Sans legend, setting the preferred size of the ChartPanel works pretty well: private static final int SIZE = 456; chartPanel. SetPreferredSize(new Dimension(SIZE, SIZE)); import java.awt. BasicStroke; import java.awt.

BorderLayout; import java.awt. Color; import java.awt. Dimension; import java.awt.

EventQueue; import java.awt.event. ActionEvent; import java.awt.geom. Ellipse2D; import java.util.

*; import javax.swing. AbstractAction; import javax.swing. JButton; import javax.swing.

JFrame; import javax.swing. JPanel; import org.jfree.chart. *; import org.jfree.chart.annotations.

XYShapeAnnotation; import org.jfree.chart.axis. NumberAxis; import org.jfree.chart.axis. NumberTickUnit; import org.jfree.chart.plot.

PlotOrientation; import org.jfree.chart.plot. XYPlot; import org.jfree.chart.renderer.xy. XYItemRenderer; import org.jfree.data.xy.

XYDataset; import org.jfree.data.xy. XYSeries; import org.jfree.data.xy. XYSeriesCollection; /** * @see http://stackoverflow.com/questions/8048652 * @see http://stackoverflow.com/questions/7231824 * @see http://stackoverflow.com/questions/7205742 * @see http://stackoverflow.com/questions/7208657 * @see http://stackoverflow.com/questions/7071057 */ public class ScatterAdd extends JFrame { private static final int N = 8; private static final int SIZE = 456; private static final String title = "Scatter Add Demo"; private static final Random rand = new Random(); private XYSeries added = new XYSeries("Added"); public ScatterAdd(String s) { super(s); final ChartPanel chartPanel = createDemoPanel(); chartPanel.

SetPreferredSize(new Dimension(SIZE, SIZE)); this. Add(chartPanel, BorderLayout. CENTER); JPanel control = new JPanel(); control.

Add(new JButton(new AbstractAction("Add") { @Override public void actionPerformed(ActionEvent e) { for (int I = 0; I SOUTH); } private ChartPanel createDemoPanel() { JFreeChart jfreechart = ChartFactory. CreateScatterPlot( title, "X", "Y", createSampleData(), PlotOrientation. VERTICAL, false, true, false); XYPlot xyPlot = (XYPlot) jfreechart.getPlot(); xyPlot.

SetDomainCrosshairVisible(true); xyPlot. SetRangeCrosshairVisible(true); XYItemRenderer renderer = xyPlot.getRenderer(); renderer. SetSeriesPaint(0, Color.

Blue); adjustAxis((NumberAxis) xyPlot.getDomainAxis(), true); adjustAxis((NumberAxis) xyPlot.getRangeAxis(), false); XYShapeAnnotation unitCircle = new XYShapeAnnotation( new Ellipse2D. Double(-1, -1, 2, 2), new BasicStroke(1.0f, BasicStroke. CAP_BUTT, BasicStroke.

JOIN_MITER, 10.0f), Color. Black); xyPlot. AddAnnotation(unitCircle); xyPlot.

SetBackgroundPaint(Color. White); return new ChartPanel(jfreechart); } private void adjustAxis(NumberAxis axis, boolean vertical) { axis. SetRange(-1.0, 1.0); axis.

SetTickUnit(new NumberTickUnit(0.5)); axis. SetVerticalTickLabels(vertical); } private XYDataset createSampleData() { XYSeriesCollection xySeriesCollection = new XYSeriesCollection(); XYSeries series = new XYSeries("Random"); for (int I = 0; I AddSeries(series); xySeriesCollection. AddSeries(added); return xySeriesCollection; } public static void main(String args) { EventQueue.

InvokeLater(new Runnable() { @Override public void run() { ScatterAdd demo = new ScatterAdd(title); demo. SetDefaultCloseOperation(JFrame. EXIT_ON_CLOSE); demo.pack(); demo.

SetLocationRelativeTo(null); demo. SetVisible(true); } }); } }.

Than you for answer, but I use chartPanel in another program. So it is resized to rectangle. I should mention that.So is there way to set same scale for bot axes?

– StaryVena Nov 9 at 8:16 You can add the ChartPanel to a container whose layout relies on preferred size, such as FlowLayout. – trashgod Nov 9 at 20:26 Ok, thanks. Still it will be nicer, if I can set the scales.

– StaryVena Nov 11 at 13:04 1 I think it's designed to scale with the container's current size. – trashgod Nov 11 at 13:56.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions