JAVA Chart

Hi,


Today I explain you how to generate graphs report in Java



JFreeChart is a free 100% Java chart library created by David Gilbert. JFreeChart makes it easy for developers to display professional quality charts in their applications.

To download JFreeChart please check here

Add this library to your project

I explain here how to generate a Pie chart in java.


Create a class called it Java_Test_Graphs

package java_test_graphs;

/**
*
* @author mahesh
*/
public class Java_Test_Graphs {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
     // TODO code application logic here
     Report_graphs objReport = new Report_graphs();
     objReport.setSize(500, 350);
     objReport.setVisible(true);
     objReport.show();
   }
}


Here Report_graphs is an another java class which is extends by javax.swing.JFrame

 see below code



package java_test_graphs;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.data.general.DefaultPieDataset;

/**
 *
 * @author mahesh
 */
public class Report_graphs extends javax.swing.JFrame {

    /** Creates new form Report_graphs */
    public Report_graphs() {
        initComponents();
        create_graph_pie_1();
    }

    public void create_graph_pie_1() {
        try {
            DefaultPieDataset pieDataset = new DefaultPieDataset();
            pieDataset.setValue("Class A", new Integer(75));
            pieDataset.setValue("Class B", new Integer(40));
            pieDataset.setValue("Class C", new Integer(60));
            pieDataset.setValue("Class D", new Integer(55));
            JFreeChart chart = ChartFactory.createPieChart("Play Group Classes Studen Report ", // Title
                    pieDataset, // Dataset
                    true, // Show legend 
                    true, // Use tooltips
                    false // Configure chart to generate URLs?
                    );
            ChartPanel chartPanel = new ChartPanel(chart);
            chartPanel.setSize(417, 240);
            jPie_1.add(chartPanel);
        } catch (Exception e) {
        }
    }
     private javax.swing.JPanel jPie_1;
    }

The Output of the above is as follows



Thank you
Mahesh Nawale


Comments

Popular posts from this blog

JTable Connection with JDBC-MYSQL and Pagination Over JTable

Database connection with mysql in Java