I just want to insert a chart (created by Graphique
class) into a panel from another class ("TabFrame" here). I am using NetBeans. So, I created a class Graphique
as you can see:
public class Graphique extends JPanel {
public Graphique(double cpm1, int temps1, double cpm2,
double temps2, double cpm3, double temps3, double cpm4,
double temps4) {
final XYDataset dataset = createDataset(cpm1, temps1,
cpm2, temps2, cpm3, temps4, cpm4,
temps4);
final JFreeChart chart = createChart(dataset);
final ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
add(chartPanel);
final XYPlot plot = chart.getXYPlot();
plot.setBackgroundPaint(Color.lightGray);
plot.setDomainGridlinePaint(Color.white);
plot.setRangeGridlinePaint(Color.white);
final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
renderer.setSeriesLinesVisible(1, false);
renderer.setSeriesShapesVisible(1, false);
plot.setRenderer(renderer);
}
public XYDataset createDataset(double cpm1, int temps1, double cpm2,
double temps2, double cpm3, double temps3, double cpm4,
double temps4) {
final XYSeries series1 = new XYSeries("log cpm net");
series1.add(temps1, cpm1);
series1.add(temps2, cpm2);
series1.add(temps3, cpm3);
series1.add(temps4, cpm4);
final XYSeriesCollection dataset = new XYSeriesCollection();
dataset.addSeries(series1);
return dataset;
}
private JFreeChart createChart(final XYDataset dataset) {
final JFreeChart chart = ChartFactory.createXYLineChart("log Chart", // chart
// title
"temps", // x axis label
"log CPM", // y axis label
dataset, // data
PlotOrientation.VERTICAL, true, // include legend
true, // tooltips
false // urls
);
return chart;
}
}
The next step is to integrate the chart the Graphique class creates into a panel (already declared thanks to the netbeans' GUI interface) in another class named here TabFrame
:
JPanel cp = new Graphique(Math.log(CMP1corBis), tempsCumule1, Math.log(CMP2corBis),
tempsCumule2,Math.log(CMP3corBis), tempsCumule3,Math.log(CMP4corBis), tempsCumule4);
PanelGraphique1.add(cp);
Why isn't this working?