tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Charts > JFreeChart > JDBC Pie Chart

JDBC Pie Chart 

JFreeChart is a free and pure java chart library for creating professional quality charts. This requires the libraries jfreechart-1.0.13.jar and jcommon-1.0.8.jar to be in classpath. The following example shows creating a simple pie chart from JDBCPieDataset. It uses H2 database to fetch the data required for rendering the pie chart. The BUG_STAT table is shown below,


File Name  :  
Author  :  Sudhakar KV
Email  :  [email protected]
package com.bethecoder.tutorials.jfree_charts.tests;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;

public class JDBCPieChart{
  public static void main(String arg[]) throws ClassNotFoundException, SQLException{

     * Initialize H2 database driver and get connection for JDBCPieDataset
    Connection conn = DriverManager.getConnection(
    DefaultPieDataset pieDataset = new JDBCPieDataset(
        conn, "select STATUS, COUNT from BUG_STAT");
    //Create the chart
    JFreeChart chart = ChartFactory.createPieChart(
      "Bug Stat Pie Chart", pieDataset, true, true, true);

    //Render the frame
    ChartFrame chartFrame = new ChartFrame("JDPC Pie Chart", chart);

It gives the following output,


bl  br