amrutha
to generate barcharts
1 Answer(s)      6 years and a month ago
Posted in : Java Beginners
Advertisement
View Answers

May 23, 2009 at 2:58 PM


Hi Friend,

1) If you want to generate bar chart using JFreeChart in java, try the following :

import org.jfree.chart.ChartFactory;
import org.jfree.chart.*;
import org.jfree.chart.JFreeChart;
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;
import java.sql.*;

public class BarChartExample {

public static void main( String[] args) throws Exception{
String query="SELECT * from chart1";
JDBCCategoryDataset dataset=new JDBCCategoryDataset("jdbc:mysql://192.168.10.112:3306/mysql";,
"com.mysql.jdbc.Driver","root","root");

dataset.executeQuery(query);
JFreeChart chart = ChartFactory .createBarChart3D(
"Bar Chart",
"Task",
"Hours",
dataset,
PlotOrientation.VERTICAL,true, true, false);
ChartFrame frame=new ChartFrame("Bar Chart",chart);
frame.setVisible(true);
frame.setSize(400,350);
}
}

2) In JSP,try the following:

<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
<%@ page import="org.jfree.chart.ChartFrame" %>
<%@ page import="org.jfree.chart.ChartFactory" %>
<%@ page import="org.jfree.chart.ChartUtilities" %>
<%@ page import="org.jfree.chart.JFreeChart" %>
<%@ page import="org.jfree.chart.plot.PlotOrientation"%>
<%@ page import="org.jfree.data.*" %>
<%@ page import="org.jfree.data.jdbc.JDBCCategoryDataset"%>

<%
String query="SELECT * from chart1";
JDBCCategoryDataset dataset=new JDBCCategoryDataset("jdbc:mysql://192.168.10.112:3306/mysql";,
"com.mysql.jdbc.Driver","root","root");

dataset.executeQuery( query);
JFreeChart chart = ChartFactory .createBarChart3D(
"Bar Chart",
"Task",
"Hours",
dataset,
PlotOrientation.VERTICAL,true, true, false);
ChartFrame frame=new ChartFrame("Bar Chart",chart);
frame.setVisible(true);
frame.setSize(400,350);
try
{
ChartUtilities.saveChartAsJPEG(new File("C:/chart.jpg"), chart, 400, 300);
}
catch (IOException e)
{
System.out.println("Problem in creating chart.");
}
%>
Thanks









Related Tutorials/Questions & Answers:
to generate barcharts - Java Beginners
to generate barcharts  Please kindly suggest: to generate a bar chart which should take data from backend(JDBC),in which Y-axis should represent...) If you want to generate bar chart using JFreeChart in java, try the following
generate file
generate file  How to generate file(.doc or .xls or .txt ) with containing data in it.By clicking on a link
Advertisements
Generate Keys
Generate Keys  hello i need code to generate key , after that send Keys to email address user. for example if you member in your website,if member not having Secret Keys not can download files if member having secret key i
Generate xml
Generate xml  hi can i generate xml file with xsd using JAXP in java. if possible please send java code. Thanks.   Please visit the following link: http://www.roseindia.net/xml/creating-xml-tree.shtml
generate report
generate report  hai, im learning php so pls help me .... what is a coding for generate report by month using php... wat is a code php for create calender and listing from database... pls someone help me
generate report
generate report  hai, im learning php so pls help me .... what is a coding for generate report by month using php... wat is a code php for create calender and listing from database... pls someone help me
To Generate Excel
To Generate Excel  hi First of all my application uses Struts2 with Springs and hibernate and am new to all of that and my requirement is as follows in a jsp there will be a link where if you click on that a dialog box
generate ID
generate ID   Statement st1=con.createStatement(); String sql="insert into employee values(emp_seq.nextval,'"+ename+"','"+eadd+"','"+ephone+"','"+email+"','"+department+"',"+Integer.parseInt(ebpay)+",20,0)"; st1.executeUpdate
generate report in swing
generate report in swing  generate report in swing
generate charts using JSP
generate charts using JSP  any one know coding for generate bar chart or pie chart using JSP
php generate link - PHP
php generate link  How can i generate links in PHP for my photo gallery app
Generate Random Numbers
Generate Random Numbers  hi,,, Please give me answer with example How do you generate random numbers within a given limit with actionscript... This function generate random numbers with in given limit
generate pdf in spring
generate pdf in spring  HOw do i generate pdf in a spring application, so that my click should query the database and a pdf should be generated and downloaded to the client side
generate pdf using jsp
generate pdf using jsp  how do i generate a pdf using jsp that should query the data from the database and write it into a pdf and download the same
generate pdf in spring
generate pdf in spring  HOw do i generate pdf in a spring application, so that my click should query the database and a pdf should be generated and downloaded to the client side
pdf generate from jsp
pdf generate from jsp  how do i generate a pdf using jsp that should query the data from the database and write it into a pdf and download the same
how to generate auto code ?
how to generate auto code ?  i wanna genrate auto code for id in core java. pls tell me code of auto genrate
Generate Employee ID (SCS-0001,SCS-0002......)
Generate Employee ID (SCS-0001,SCS-0002......)  Hello everyone i am beginner in java and i am working on my major project I want to generate bill number and employee number like SCS-0001 and so on and bill number like SCS/'date
jsf: generate another panelGrid
jsf: generate another panelGrid  hello the following is my code print("code sample"); <%@ taglib uri="http://java.sun.com/jsf/html" prefix... generate another panelgrid with the same number of columns and rows (Each time I
generate Email - JSP-Servlet
generate Email  Hi I need to generate an automated email and need to send it to the client like an confirmation email after registering to my website. I m using jsp code. Please help me out with this issue.  Hi friend
need to generate ID
need to generate ID  hai, i need to generate ID i.e when i select addemploye option and submit, it should generate a emp ID which is 1 greater than... it should generate empID as 5 and i should continue with inserting other values like
need to generate ID
need to generate ID  hai, i need to generate ID i.e when i select addemploye option and submit, it should generate a emp ID which is 1 greater than... it should generate empID as 5 and i should continue with inserting other values like
how to generate bank account number?
how to generate bank account number?  how to generate account number?or format or rules for bank account number
How to generate XML from XSD?
How to generate XML from XSD?  Hi Experts, I have a xsd with me. I want to generate XML files based on the XSD with fields filled out from the database tables. Please Help me out
Generate pdf file - JSP-Servlet
Generate pdf file   Hi Friends, How to generate the pdf file for the jsp page or in servets  Hi Friend, You need to download itext api. After that set the classpath and try the following code
Java program to generate the total count
Java program to generate the total count  I need a java program which would take a text file as an input and scans through it to generate the output. For Ex. : If the text file contains the following information: There is/are 3
how to generate code - Java Beginners
how to generate code   hi friends, this is poornima i want to generate code about online shopping by using servlets,jsp,html,jdbc and eclipse (IDE) could you please tell me about what are steps included. Thanks in advance
how to generate timetable - JSP-Servlet
how to generate timetable  can i have a jsp/servlet code for generating timetable for examinations for university like courses btech,cse ece etc... By giving starting date and ending date it will automatically generate
how to generate pdf file in struts
how to generate pdf file in struts  I am developing a struts application.I am having one registration form when i am submitting the form the values are stored in database,the database name is registration. In another form i am
how to generate pdf file in struts
how to generate pdf file in struts  I am developing a struts application.I am having one registration form when i am submitting the form the values are stored in database,the database name is registration. In another form i am
generate graf report.. - JSP-Interview Questions
generate graf report..  How to generate report(graf) using jsp code