Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package FECTester; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import javax.swing.JFrame; import org.jfree.chart.plot.PlotOrientation; import org.jfree.data.xy.XYSeries; import org.jfree.data.xy.XYSeriesCollection; /** * * @author Wojciech Urbaczyk * @version 1.0 */ public class Chart extends JFrame { XYSeriesCollection dataset = new XYSeriesCollection(); public Chart(String name, String xLabel, String yLabel) { super(name); JFreeChart lineChart = ChartFactory.createXYLineChart(name, xLabel, yLabel, dataset, PlotOrientation.VERTICAL, true, true, false); ChartPanel chartPanel = new ChartPanel(lineChart); chartPanel.setPreferredSize(new java.awt.Dimension(600, 450)); setContentPane(chartPanel); this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); this.setSize(600, 450); this.setResizable(false); this.setVisible(false); } public void addSeries(String name, double[] tabX, double[] tabY) { XYSeries series = new XYSeries(name); if (tabX.length == tabY.length) { for (int i = 0; i < tabX.length; i++) { series.add(tabX[i], tabY[i]); } } try { XYSeries s = dataset.getSeries(name); dataset.removeSeries(s); } catch (Exception e) { } dataset.addSeries(series); } public void clear() { dataset.removeAllSeries(); } }