I have generated a few charts, as per an assignment, and for data analysis I would like the domain axis to scale to my specifications, rather than to automatically fit the data in each series.
I found a solution here, which seemed very simple to follow: JFReeChart x axis scale
However, after I create my plot, with the code below, it seems like the method does not exist.
Is the method setDomainAxis() one that is included in the libraries or do I have to create it myself? Or have I violated some fundamental rule of java that has nothing to do with JFreeChart? I am a beginner java programmer, so please inform your answer accordingly. Thanks!
Here is my XYPlot class:
public class XYPlot extends JFrame {
private String title;
private String xAxis;
private String yAxis;
private XYSeriesCollection dataset;
public XYPlot(String header, String graphTitle, String xax, String yax) {
super(header);
xAxis = xax;
yAxis = yax;
title = graphTitle;
XYPlot myPlot;
// dataset = dat;
}
public void setTit(String newTitle){
title = newTitle;
}
public void setXAxis(String X){
xAxis = X;
}
public void setYAxis(String Y){
xAxis = Y;
}
public void passData(XYSeriesCollection data){
dataset = data;
}
public void createChart(XYSeriesCollection dataIn){
final JFreeChart chart = ChartFactory.createXYLineChart(
title,
xAxis,
yAxis,
dataIn
);
final ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(1200, 800));
setContentPane(chartPanel);
}
And here is the implementation of the plot in my main program:
public static void seriesPlotter(XYSeriesCollection dataset, String title, String header, String xAxis, String yAxis) {
XYPlot myPlot = new XYPlot(header, title, xAxis, yAxis);
myPlot.createChart(dataset);
NumberAxis domain = new NumberAxis();
domain.setTickUnit(1);
myPlot.setDomainAxis(domain);
myPlot.pack();
myPlot.setVisible(true);
}