But I'm also having a problem scaling the x-axis and the y-axis so they have the same scale i.e. length between ticks of the 2 axis should be exactly the same.
Here is what I've been able to do so far but that's not that good...
Code: Select all
import java.awt.Dimension;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
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.data.xy.CategoryTableXYDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
public class ScatterPlotDemo extends ApplicationFrame {
private static final long serialVersionUID = 1L;
public ScatterPlotDemo(String title) {
super(title);
CategoryTableXYDataset dataset = new CategoryTableXYDataset();
dataset.add(2, 4, "a");
dataset.add(11, 2, "b");
JFreeChart chart = ChartFactory.createScatterPlot("titre", "x", "y", dataset, PlotOrientation.VERTICAL, true, true, false);
ChartPanel chartPanel = new ChartPanel(chart, false);
chartPanel.setPreferredSize(new Dimension(500, 270));
setContentPane(chartPanel);
XYPlot plot = chart.getXYPlot();
NumberAxis xAxe = (NumberAxis) plot.getDomainAxis();
xAxe.setLabel("xXx");
xAxe.setTickUnit(new NumberTickUnit(1));
NumberAxis yAxe = (NumberAxis) plot.getRangeAxis();
yAxe.setLabel("yYy");
yAxe.setTickUnit(new NumberTickUnit(1));
}
public static void main(String[] args) {
ScatterPlotDemo demo = new ScatterPlotDemo("demo");
demo.pack();
demo.setVisible(true);
}
}