Home Answers Viewqa JSP-Servlet how to generate a bar chart on a JSP PAGE using the arraylist object passed form the servlet.(using jfreechart)

 
 


Aarushi Agarwal
how to generate a bar chart on a JSP PAGE using the arraylist object passed form the servlet.(using jfreechart)
2 Answer(s)      a year and 7 months ago
Posted in : JSP-Servlet

I have created a servlet.In this,i have retrieved a record from MS Access database in an arraylist i.e. my arraylist contains only one object(rollno,name,marks1,marks2,marks3,marks4) from the database.now i have to pass this arraylist object to a jsp page and on that jsp page i have to display a graph between a student semester-marks .(semesters on x-axis and marks1,marks2,marks3,marks4 on y-axis) using JFREECHART.how can i do it.please reply soon.I am attaching my servlet and jsp page beneath. please reply asap.Its urgent.

Here is my code:

arraylist.java(servlet)

import java.util.ArrayList;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author AARUSHI
 */
class database
 {
     int roll;
  String name;
  int marks1;
   int marks2;
    int marks3;
     int marks4;
  public database(int r,String nm,int m1,int m2,int m3,int m4)
   {

      roll=r;
      name=nm;
      marks1=m1;
      marks2=m2;
      marks3=m3;
      marks4=m4;
   }
    @Override
  public String toString()
   {
      return roll + ":" + name + ":" + marks1 + ":" + marks2 + ":" + marks3 + ":" + marks4;
   }
}
public class arraylist extends HttpServlet {

    /**
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        ArrayList<database> v = new ArrayList<database>();
        database db;

        try {
             int rollno=Integer.parseInt(request.getParameter("txtroll"));

           Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con=DriverManager.getConnection("jdbc:odbc:cdotdsn");

    PreparedStatement ps=con.prepareStatement("select * from cdottable where rollno=?");
        ps.setString(1,""+rollno);
        ResultSet rs=ps.executeQuery();
        out.println("hello1");

        while(rs.next())
        {
           //  out.println("1st "+rs.getString(1));
         // out.println("2nd "+rs.getString(2));
        //out.println("3rd "+rs.getString(3));
      //out.println("4th "+rs.getString(4));
         //  out.println("5th "+rs.getString(5));
         //  out.println("6th "+rs.getString(6));
      int r=Integer.parseInt(rs.getString(1));
       String nm=rs.getString(2);
       int m1=Integer.parseInt(rs.getString(3));
       int m2=Integer.parseInt(rs.getString(4));
       int m3=Integer.parseInt(rs.getString(5));
       int m4=Integer.parseInt(rs.getString(6));
       out.println(r+ nm + m1 + m2 + m3 + m4);
       out.println("abc");
       db=new database(r,nm,m1,m2,m3,m4);
        v.add(db);
       int m=v.size();
         out.println(m);
       out.println( v );
        }
       for (int i=0;i<v.size();i++)
{
//out.println("<tr><td><br>name======" + rowArray.get(i) + "</td></tr>");
request.getSession().setAttribute("myArrayList",v);
RequestDispatcher requestDispatcher=getServletContext().getRequestDispatcher("/myjsp.jsp");
requestDispatcher.forward(request,response);
}


        con.close();
        }
  catch(Exception e)
        {
           out.println(e);
        }

    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}

Jsp page(myjsp.jsp)

<%-- 
    Document   : myjsp
    Created on : Oct 19, 2011, 8:22:50 PM
    Author     : AARUSHI
--%>

<%@page import="java.sql.*"%>
<%@page import="java.util.*"%>
<%@page import="java.util.ArrayList"%>
<%@ page session="true"%>
<%@page import="java.io.*"%>
<%@page import="javax.servlet.*"%>
<%@page import="java.io.*"%>
<%@page import="p1.*"%>



<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>


<%
try
{

ArrayList pageArray = new ArrayList();
pageArray.add(request.getSession().getAttribute("myArrayList"));
//pageArray.add(request.getAttribute("myArrayList")) ;
for (int i=0;i<pageArray.size();i++)
{
out.println(pageArray.get(i));
}
out.println(pageArray.size());
}
catch(Exception e)
{
out.println(e);
e.printStackTrace();
}
%>


    </body>
</html>

my access database contains the follwing fields(rollno,name,marks1,2,3,4). Please answer my query soon.

View Answers

October 20, 2011 at 11:27 AM



October 20, 2011 at 11:56 AM


thankyou for the code.But this is not wat i m asking.tellme how can I generate the bar graph in my code attached i.e. myjsp.jsp.

I have sent the data from servlet to jsp already.









Related Pages:
how to generate a bar chart on a JSP PAGE using the arraylist object passed form the servlet.(using jfreechart)
how to generate a bar chart on a JSP PAGE using the arraylist object passed form the servlet.(using jfreechart)  I have created a servlet.In this,i... the database.now i have to pass this arraylist object to a jsp page and on that jsp page
Create a bar chart in JSP page using JFreeChart
Create a bar chart in JSP page using JFreeChart       This Example shows you how to create a bar chart in JSP page using JFreeChart. Code given below creates a bar chart
Bar Chart in JSP - JSP-Servlet
Bar Chart in JSP  Hi I am creating Bar chart using Jfree charts in JSP. Please advise me how to customize it. Like controlling the colors, width for each bar, showing values above the bar .  hi friend, Use
Create a 3D bar chart in JSP page using JFreeChart
Create a 3D bar chart in JSP page using JFreeChart       This Example shows you how to create a 3D bar chart in jsp page using JFreeChart. Code given below creates a bar
Stacked Bar Chart using JFreeChart
Stacked Bar Chart using JFreeChart   ... bar chart using JFreeChart. In the code given below we have extended class.... createStackedBarChart(): This method is used to create stacked bar chart for given values
Create a pie chart in jsp page using JFreeChart
Create a pie chart in jsp page using JFreeChart... to create a pie chart in jsp page using JFreeChart. Code given below creates... is used to create bar chart for given values. It takes title, category axis label
Create area chart in JSP page using JFreeChart
Create area chart in JSP page using JFreeChart... to create a area chart in JSP page using JFreeChart. Code given below creates a area...(): This method is used to create bar chart for given values. It takes title
Bar chart with J table
tell me how can I make a bar graph that will display the data from my table.I tried using the code from your page (http://www.roseindia.net/chartgraphs/bar...Bar chart with J table  Hi I'm new in Java and I have a application
Stacked Bar Chart Example using JFreeChart
Stacked Bar Chart Example using JFreeChart... a Stacked bar chart using JFreeChart. Bar chart will represent scores of two team... to create stacked bar chart for given values. It  takes title, domain axis
create bar chart in jsp using msaccess database
create bar chart in jsp using msaccess database  thanks for reply...) org.apache.jsp.bar<em>jsp.</em>jspService(bar_jsp.java:57...); JFreeChart chart = ChartFactory .createBarChart3D( "Test", "Id", "Score
Bar Chart using JSP and tooltip to be implemented
Bar Chart using JSP and tooltip to be implemented  Hi Deepak, I have generated a bar chart in JSP using JFreeCharts but I could not get the tool tip for that. Please any one suggest me how to do that or provide some code. Help
How to create bar chart using database values
How to create bar chart using database values  How to create bar chart using database values i.e excellent,good,average fields using jsp?It is like opinion poll.I want to show how many votes are came for excellent,good,average
how to create bar chart in jsp using msaccess database
how to create bar chart in jsp using msaccess database  type... in the jsp file: /bar.jsp Generated servlet error: C:\Program Files\Apache Software Foundation\Tomcat 5.0\work\Catalina\localhost\chetana\org\apache\jsp\bar_jsp.java
How to display Jfreechart from servlet in jsp web page at specified location
How to display Jfreechart from servlet in jsp web page at specified... to display the chart in web page. I generated the chart using Jfreechart in Servlet which is in image format.plz sir give me the code to display this chart
Draw Statistical chart in jsp
chart in jsp by getting values from database.. To draw a bar chart, we have used  JFreeChart Library. JFreeChart is a chart library used to generate different... Draw Statistical chart in jsp   
generate charts using JSP
generate charts using JSP  any one know coding for generate bar chart or pie chart using JSP
how to create a bar chart in jsp by fetching value from oracle databse?
how to create a bar chart in jsp by fetching value from oracle databse?  i want to show the population of various states in a bar chart in my jsp page by fetching the data from my oracle table. i am using my eclipse as my IDE
Stacked 3d Bar Chart Example using JFreeChart
Stacked 3d Bar Chart Example using JFreeChart... a Stacked 3d bar chart using JFreeChart. Bar chart will represent the score... is used to create stacked bar chart for given values. It takes title, domain
create bar chart in jsp using msaccess database
create bar chart in jsp using msaccess database  type Exception... Foundation\Tomcat 5.0\work\Catalina\localhost\chetana\org\apache\jsp\bar_jsp.java:57... occurred at line: 8 in the jsp file: /bar.jsp Generated servlet error
Bar Chart
Bar Chart       This section illustrates you how to create bar chart using html in jsp. To draw a bar chart, we have used html tags. In this, firstly
Horizontal Bar Chart Example using JFreeChart
Horizontal Bar Chart Example using JFreeChart... a Horizontal bar chart using JFreeChart. This example showing you match.... createBarChart():  This method is used to create bar chart for given values
Bar charts and jsp
Bar charts and jsp  Hi, How to generate Dynamic Bar Chart Images using jsp with placing any image location in weebroots? Thanks in advance
Page object - JSP-Servlet
Page object  Hello friends, How can we make use of PAGE object of implicit JSP object. If this is possible explain me about it's methods. I did not find any methods or explanation of this object. Pls help me
Box And Whisker Chart Example using JFreeChart
Box And Whisker Chart Example using JFreeChart       This Example shows you how to create a box and whisker chart using JFreeChart. Code of the chart given below
Bar chart implementation in PHP
Bar chart implementation in PHP  How to implements reports in bar graphs by using PHP
Jfreechart chart display problem
Jfreechart chart display problem  Using JSP and Jfreechart displays the chart fine on an internal browser in eclipse but doesnt display it on Chrome..."); dataset.executeQuery(query); JFreeChart chart = ChartFactory.createLineChart
Create multiple pie chart in single frame using JFreeChart
you how to create a multiple pie charts in a single frame in jsp page using... Create multiple pie chart in single frame using JFreeChart.... createMultiplePieChart(): This method is used to create bar chart
ChartFrame in Jfreechart - JSP-Servlet
am developing line chart in JSP and the code is: My problem is that the chart is created and also saved in the specified location.. But its not displaying on the page i.e chartframe portion
graph generation using jfreechart and retrieving values from the database
database using prepared statement and then display the bar graph using jfreechart API .This whole retrieval and display of chart is to be done in a servlet...graph generation using jfreechart and retrieving values from the database 
Chart & Graphs Tutorials in Java
This Example shows you how to create a 3D bar chart in jsp page using JFreeChart... JFreeChart This Example shows you how to create a bar chart in JSP page... This Example shows you how to create a area chart in JSP page using JFreeChart
Stacked Bar Chart
Stacked Bar Chart  How to display a stacked bar chart using java from the values stored in the ms access database?Plzz help..its urgent
JFreechart Stacked Bar Chart
JFreechart Stacked Bar Chart JFreechart provides a way to create various charts by just using the methods of different classes. You are well aware of bar... Bar Chart. This chart actually displays the result of multiple queries stacks
Create a polar chart using JFreeChart
Create a polar chart using JFreeChart  ... a polar chart using JFreeChart. Code given below creates a simple polar chart...(): This method is used to create bar chart for given values. It takes title, dataset
Bar Chart
. Description of Program  For creating a Bar chart we use the object... for a Bar chart we have to create an object of DefaultCategoryDataset type...; JFreeChart chart = ChartFactory.createBarChart("BarChart using JFreeChart
Bar Chart Example using JFreeChart
Bar Chart Example using JFreeChart       This Example shows you how to create a bar chart using JFreeChart. Code given below creates a bar chart of scores of two teams
jfreechart display from access database data.
the bar graph using jfreechart API .This whole retrieval and display of chart is to be done in a servlet.. Note that it is a access made database. How can I... jsp code. <%@ page import="java.sql.*" %> <%@ page import="java.io.
Read Excel file and generate bar graph
Read Excel file and generate bar graph In this tutorial, you will learn how to read an excel file and generate bar graph. Here is an example that reads... the data of excel file, we have generated a bar chart. The given code uses Apache
Category Step Chart Example using JFreeChart
Category Step Chart Example using JFreeChart... a category step chart using JFreeChart. Code of the chart shows you run rate... object is used to create new chart according CategoryPlot class object
Bar Chart in Java
Bar Chart in Java      ... to draw simple bar chart in Java. A bar chart (bar graph) is a way of comparing two... chart in Java. To draw a bar chart, the variables minvalue, maxvalue of double type
Candle Stick Chart Example using JFreeChart
Candle Stick Chart Example using JFreeChart       This Example shows you how to create a candle stick chart using JFreeChart. Code of the chart given below shows
Create a dual axis chart using JFreeChart
Create a dual axis chart using JFreeChart       This Example shows you how to create a dual axis chart using JFreeChart. Code given below creates a simple dual axis
How to generate the pdf file using jsp - JSP-Servlet
How to generate the pdf file using jsp  Hi how to generate the pdf file in jsp  Hi Friend, Try the following code: Thanks
How to use an object properties in jsp page
How to use an object properties in jsp page  I have a arraylist of objects 'User' populated using struts 2 action class while loading that jsp page. In that JSP I have included another jsp using following tag: Here instead
Pie chart on jsp
Pie chart on jsp  how can i create a pie chart on a jsp page using jfreechart which takes values from my databaase??   Here is a jsp code that creates a pie chart using JFreechart api and takes the value from
how to display each arraylist value on new page in jsp
how to display each arraylist value on new page in jsp  hi!!!! i want to display each arraylist value on new page in jsp????? and also want to access the arraylist values using next button..... any help would be appreciated
java bar charts and jsp
java bar charts and jsp  Hi, Can any one help me out in how to create java bar charts using jsp with the help of data base table values? thanks.../jsp/draw-statistical-chart-jsp.shtml
how to show value and percentage in piechart sections from database using jfreechart
how to show value and percentage in piechart sections from database using jfreechart  Hii Sir, I made a pie chart from database using... Method /** * This method creates a test pie chart using internally
Jfreechart zoomin and zoomout - Framework
Jfreechart zoomin and zoomout  how to zoomin and zoom out chart using button plus and minus or slide bar in jFree chart
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
Create a Pie Chart in jsp Page using JFree Chart
Create a Pie Chart in jsp Page using JFree Chart  Hello Sir I followed ur tutorial on "CREATE A PIE CHART IN JSP PAGE USING JFREE CHART... the pie chart report and after that save it to the desired location.Kindly help me

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.