Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


anitha.a
hai
4 Answer(s)      2 years and 5 months ago
Posted in : Java Beginners


hai this is anitha , i am persuing my B.Tech. 3rd year,i am doing a mini project,my task is to develope a code in java,to generate a graph using sql database values. so,kindly help me with my mini project.please try to reply me as early as possible


Advertisement
View Answers

May 16, 2012 at 11:53 AM


Java Line Chart using jfreechart

The given code retrieves the data from the database and create a line chart. The jfreechart api has provided some classes which can be used directly to connect database values with the chart.

import java.sql.*;
import org.jfree.ui.*;
import org.jfree.data.*;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.jdbc.JDBCCategoryDataset;

public class Chart{
    public static void main(String[] args) throws Exception {

           String query = "SELECT * from cricket_match";
           JDBCCategoryDataset dataset = new JDBCCategoryDataset("jdbc:mysql://localhost:3306/test", 
                "com.mysql.jdbc.Driver","root", "root");
           dataset.executeQuery(query);
           JFreeChart chart =  
                ChartFactory.createLineChart("Score", "Runs", "Overs",
            dataset, PlotOrientation.VERTICAL, true, true, false);

           ChartPanel chartPanel = new ChartPanel(chart);
                chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
                ApplicationFrame f = new ApplicationFrame("Chart");
                f.setContentPane(chartPanel);
                f.pack();
                f.setVisible(true);
    }
}


May 16, 2012 at 12:01 PM


Java XY Line Chart using jfreechart

The given code retrieves the data from the database and create a xy line chart. The jfreechart api has provided some classes which can be used directly to connect database values with the chart.

import java.sql.*;
import org.jfree.chart.*;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.xy.*;
import org.jfree.data.*;

public class Chart{
public static void main(String arg[])throws Exception{
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root" );
        Statement st=conn.createStatement();
        ResultSet rs=st.executeQuery("SELECT * from cricket_match");
  XYSeries series = new XYSeries("");
  while(rs.next()){

  series.add((double)rs.getInt("runs"),(double)rs.getInt("overs"));
  }
  XYDataset xyDataset = new XYSeriesCollection(series);
  JFreeChart chart = ChartFactory.createXYLineChart
  ("Match Score", "Runs", "Overs",xyDataset, PlotOrientation.VERTICAL, true, true, false);
  ChartFrame frame1=new ChartFrame("",chart);
  frame1.setVisible(true);
  frame1.setSize(300,300);
  }
}


May 16, 2012 at 12:06 PM


Java Bar Chart using jfreechart

The given code retrieves the data from the database and create a bar chart. The jfreechart api has provided some classes which can be used directly to connect database values with the chart.

import java.sql.*;
import java.io.*;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.*;
import org.jfree.data.jdbc.JDBCCategoryDataset;

public class Chart {
        public static void main(String[] args) throws Exception {

               String query = "SELECT * from chart";
               JDBCCategoryDataset dataset = new JDBCCategoryDataset(
                "jdbc:mysql://localhost:3306/test", 
                "com.mysql.jdbc.Driver","root", "root");
               dataset.executeQuery(query);
               JFreeChart chart =  
                ChartFactory.createBarChart3D("Test", "Id", "Score",
                dataset, PlotOrientation.VERTICAL, true, true, false);
               try {
               ChartUtilities.saveChartAsJPEG(new File("C:/chart.jpg"),
                chart,400, 300);
               } catch (IOException e) {
               System.out.println("Problem in creating chart.");
  }
        }
}


May 16, 2012 at 12:08 PM


Java Pie Chart using jfreechart

The given code retrieves the data from the database and create a pie chart. The jfreechart api has provided some classes which can be used directly to connect database values with the chart.

import java.sql.*;
import java.io.*;
import org.jfree.ui.*;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.data.*;
import org.jfree.data.jdbc.JDBCPieDataset;

public class Chart {
        public static void main(String[] args) throws Exception {

                String query = "SELECT * from chart";
                JDBCPieDataset dataset = new JDBCPieDataset(
                                "jdbc:mysql://localhost:3306/test", "com.mysql.jdbc.Driver",
                                "root", "root");

                dataset.executeQuery(query);
                JFreeChart chart = ChartFactory.createPieChart("Test", dataset, true,
                                true, false);
                ChartPanel chartPanel = new ChartPanel(chart);
                chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
                ApplicationFrame f = new ApplicationFrame("Chart");
                f.setContentPane(chartPanel);
                f.pack();
                f.setVisible(true);

        }
}


Related Tutorials/Questions & Answers:
hai
hai   when we click on submit button request doesnot go to next servlet instead of that that servlet simply downloaded why? can tell me plz   It seems that the problem lies in your code. Anyways, we are providing you
hai
hai   I am using windows 7 with 32 bit os I installed java 1.6 version I also installed oracle 10g. When I am trying to execute jdbc-odbc programs it simply displays "jdbc drivers not found" plz help me   Java
Advertisements
hai
hai  hai this is anitha , i am persuing my B.Tech. 3rd year,i am doing a mini project,my task is to develope a code in java,to generate a graph using sql database values. so,kindly help me with my mini
hai
hai
hai
hai
hai this is sql question
hai this is sql question  what are tables in home appliances web application
hai java - Java Beginners
hai java  what do u mean by unchecked exception and checked exception? and do any java pgm will run with out thread concept... and what si thread...  Hi Friend, Please visit the following link: http
matrix addition
matrix addition  hai
matrix addition
matrix addition  hai
matrix substraction
matrix substraction  hai
matrix substraction
matrix substraction  hai
j2me exception - MobileApplications
j2me exception  Hai
matrix determination in java
matrix determination in java  hai
matrix polynamial addtion
matrix polynamial addtion  hai
jdbc
jdbc  Hai , Give a steps for jdbc connectivity
jsp webapplication
jsp webapplication  hai Good mring to all
need sourcecode - Java Beginners
need sourcecode  Hai, I need program for packetization for videos
SWING FRMES
SWING FRMES  hai SIR? HOW TO DESIGN swing Frames send source code
SWING FRMES
SWING FRMES  hai SIR? HOW TO DESIGN swing Frames send source code
query optimization
query optimization  hai ! i need a code in java for database query optimization.plz help
for loop
for loop  hai, I need to write java program to print numbers in "X" format
String tokenizer class
String tokenizer class  Hai... What is string tokenizer class? & what's its purpose
String tokenizer class
String tokenizer class  Hai... What is string tokenizer class? & what's its purpose
String tokenizer class
String tokenizer class  Hai... What is string tokenizer class? & what's its purpose
length in array
length in array  hai wat s length in array and where it s used
Interface vs abstract class
Interface vs abstract class  Hai, Is there any possible to defining abstract methods in Interface
jsp
jsp  hai please give me the table grid code code for jsp
 

 

 

DMCA.com