Menu

Piechart Example

Masta Suvi

unfortunatly sourceforge doesn't allow more than 5 screenshot.

if you want to see how the piechart looks like have a look at the
freecode page http://freecode.com/projects/jchartlib
and click on the screenshot there.

Here is a sample code for a piechart

/**

  • JChartLib Demo App for a piechart
  • @author Silvio Schneider
    */
    import com.bitagentur.chart.JChartLibPiechart;
    import com.bitagentur.data.JChartLibDataSet;

import com.bitagentur.data.JChartLibSerie;
import com.bitagentur.renderer.JChartLibPanel;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.util.Random;
import javax.swing.JFrame;

/**

  • A simple demonstration application showing how to create a pie chart.
    *
    */
    public class JChartLibApp_piechart extends JFrame implements WindowListener {

    /**

    • Creates a new Application Frame
      */
      public JChartLibApp_piechart() {
      super("JChartLib Demo Appllication");

      final JChartLibDataSet dataset = createDataset();
      final JChartLibPiechart chart = createChart(dataset);
      final JChartLibPanel chartPanel = new JChartLibPanel(chart);
      chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
      setContentPane(chartPanel);
      }

    /**

    • Creates a sample dataset.
    • @return a sample dataset.
      */
      private JChartLibDataSet createDataset() {
      //or by generating a Dataserie object
      JChartLibSerie values1 = new JChartLibSerie("Fruits");
      values1.addValue("Apple", 1);
      values1.addValue("Banana", 1);
      values1.addValue("Orange", 1);
      values1.addValue("Tomato", 1);

      final JChartLibDataSet dataset = new JChartLibDataSet();
      dataset.addDataSerie(values1); //adds the Apples

      return dataset;
      }

    /**

    • Creates a chart
    • @param dataset the data for the chart.
    • @return a new chart
      */
      private JChartLibPiechart createChart(final JChartLibDataSet dataset) {

      // create the chart with title and axis names
      final JChartLibPiechart chart = new JChartLibPiechart(
      "yammi fruitpie", // chart title
      "", // x axis text
      "", // y axis text
      dataset // data
      );

      return chart;
      }

    /**

    • Main method - DEMO Application for JChartLib
      *
    • @param args the command line arguments
      */
      public static void main(final String[] args) {
      System.out.println("JChartLibApp started");
      final JChartLibApp_piechart app = new JChartLibApp_piechart();
      app.addWindowListener(app);
      app.pack();
      app.setVisible(true);
      }

    @Override
    public void windowOpened(WindowEvent e) {
    //Nothing to do
    }

    @Override
    public void windowClosing(WindowEvent e) {
    //Exit and goodby
    if (e.getWindow() == this) {
    dispose();
    System.out.println("Thanks for using the JChartLibApp");
    System.exit(0);
    }
    }

    @Override
    public void windowClosed(WindowEvent e) {
    //Nothing to do
    }

    @Override
    public void windowIconified(WindowEvent e) {
    //Nothing to do
    }

    @Override
    public void windowDeiconified(WindowEvent e) {
    //Nothing to do
    }

    @Override
    public void windowActivated(WindowEvent e) {
    //Nothing to do
    }

    @Override
    public void windowDeactivated(WindowEvent e) {
    //Nothing to do
    }
    }


MongoDB Logo MongoDB