Add a JFreeChart in to JPanel

后端 未结 4 883
暖寄归人
暖寄归人 2021-01-11 11:04

if i have a my Jpanel and a my JFreeChart. How can I add this Chart in to the JPanel?

XYSeries series = new XYSeries(\"XYGraph\");
   series.add(1, 1);
   se         


        
相关标签:
4条回答
  • 2021-01-11 11:08

    I was having the same problem but I was able to identify a way to solve this.

    JPanel panel = new JPanel();
    		panel.setBackground(new Color(255, 102, 51));
    		panel.setBounds(50, 64, 955, 888);
    		frame.getContentPane().add(panel);
    		panel.setLayout(null); //Absolute Layout
    
    XYSeries series = new XYSeries("XY Chart");
    		XYSeriesCollection dataset = new XYSeriesCollection(series);
    		JFreeChart chart = ChartFactory.createTimeSeriesChart("Testing Chart", "Date", "Average Profit", dataset);
    		
    		ChartPanel chartPanel = new ChartPanel((JFreeChart) null);
    		chartPanelH2S.setChart(chart);
    		chartPanelH2S.setBounds(39, 193, 419, 309);
    		panel.add(chartPanel);
    frame.setVisible(true);

    Hope this helps

    0 讨论(0)
  • 2021-01-11 11:10

    Here is a good tutorial to lead you further : How to embed JFreeChart in JPanel

    0 讨论(0)
  • 2021-01-11 11:23

    From an old java forums thread

    JPanel jPanel1 = new JPanel();
    jPanel1.setLayout(new java.awt.BorderLayout());
     ..
    ChartPanel CP = new ChartPanel(chart);
    .. 
    jPanel1.add(CP,BorderLayout.CENTER);
    jPanel1.validate();
    
    0 讨论(0)
  • 2021-01-11 11:25
    JFreeChart chart = new JFreeChart("Cos(x) and Cos^2(x) versus x", parent);
    ChartPanel myChart = new ChartPanel(chart);
    myChart.setMouseWheelEnabled(true);
    jPanel1.setLayout(new java.awt.BorderLayout());
    jPanel1.add(myChart,BorderLayout.CENTER);
    jPanel1.validate();
    
    0 讨论(0)
提交回复
热议问题