问题
I have been trying to do this..
JFreeChart chart = createChart(createDataset());
jPanel1 = new ChartPanel(chart, false);
this JPanel1 is inside a JFrame ( its a JFrame Form of Netbeans, so i have some labels and textAreas)
jPanel1 is fixed inside designer of Netbeans .. at some place after doing other work of data now i want a chart of my data under all the text about data..
I tried other solutions like casting the JFreeChart to jPanel. also
JFreeChart chart = createChart(createDataset());
JChartPanel P=new ChartPanel(chart,false);
jPanel1.add(P);
Actual Code :
public class NucleotideComposition extends JFrame{
public NucleotideComposition(String filename) {
DNA dna=new DNA(filename);
int count
moleculeName.setText(dna.getSeq_name());
Length.setText(Integer.toString(count = dna.length()));
JFreeChart chart = createChart(createDataset(dna.countA(),dna.countT,dna.Countc,dna.countG));
jPanel1 = new ChartPanel(chart, false);
}
private static PieDataset createDataset(int A,int T,int C,int G) {
DefaultPieDataset dataset = new DefaultPieDataset();
dataset.setValue("A", A);
dataset.setValue("T", T);
dataset.setValue("G", C);
dataset.setValue("C", G);
return dataset;
}
private static JFreeChart createChart(PieDataset dataset) {
JFreeChart chart = ChartFactory.createPieChart3D(
"Nucleotide Composition", // chart title
dataset, // data
true, // include legend
true,
true
);
PiePlot3D pieplot3d = (PiePlot3D) chart.getPlot();
pieplot3d.setStartAngle(270D);
pieplot3d.setDirection(Rotation.ANTICLOCKWISE);
pieplot3d.setForegroundAlpha(0.6F);
Rotator rotator = new Rotator((PiePlot3D) chart.getPlot());
rotator.start();
return chart;
}
}
来源:https://stackoverflow.com/questions/20297961/how-to-add-chartpanel-in-jpanel-inside-a-jframe