How to add ChartPanel in JPanel inside a JFrame

一曲冷凌霜 提交于 2019-12-08 13:11:48

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!