I wanted to use JFreeChart in my applet application, here is the way how to include the generated graph image into your applet. You have to bind the applet's Graphics with the Image generated by the jfreechart. Here's the main trick: chart.draw( (Graphics2D)g,getBounds());
public void init() { // It is required but does not need anything. }
// This method gets called when the applet is terminated // That's when the user goes to another page or exits the browser. public void stop() { // no actions needed here now. }
// The standard method that you have to use to paint things on screen // This overrides the empty Applet method, you can't called it "display" for example.
public void paint(Graphics g) { //method to draw text on screen // String first, then x and y coordinate. // Create a simple XY chart XYSeries series = new XYSeries("XYGraph"); series.add(1, 1); series.add(2, 2); series.add(3, 1); series.add(4, 9); series.add(5, 10); series.add(6, 60); // Add the series to your data set XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(series); // Generate the graph JFreeChart chart = ChartFactory.createXYLineChart("XY Chart", // Title "x-axis", // x-axis Label "y-axis", // y-axis Label dataset, // Dataset PlotOrientation.VERTICAL, // Plot Orientation true, // Show Legend true, // Use tooltips false // Configure chart to generate URLs? ); chart.setAntiAlias(true); if ( chart!=null ) { chart.draw( (Graphics2D)g,getBounds()); //repaints the whole chart } }