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



Home Answers Viewqa JSP-Servlet how to show value and percentage in piechart sections from database using jfreechart

Have Programming Question? Ask it here!
 
 
 


vikas pandey
how to show value and percentage in piechart sections from database using jfreechart
1 Answer(s)      a year and 11 months ago
Posted in : JSP-Servlet


Hii Sir, I made a pie chart from database using jfreechart.Now I need to display the values and their percentage in the sections of the piechart.kindly help me out as i am in need of this in my live project. thnx in advance......

import java.io.IOException; import java.io.OutputStream; import javax.servlet.*; import javax.servlet.http.*; import java.awt.Color; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartUtilities; import org.jfree.chart.JFreeChart; import org.jfree.data.general.DefaultPieDataset; 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.PiePlot; import org.jfree.chart.plot.PlotOrientation; import org.jfree.data.*; import org.jfree.data.jdbc.JDBCCategoryDataset; import org.jfree.data.jdbc.JDBCPieDataset;

public class piechart extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{ doTestbarChart(request, response); } // End Method

/** * This method creates a test pie chart using internally * generated data. This method can be used to test the * basic JFreeChart setup and the basic servlet * configuration. * * @param request The HttpServletRequest request, * which contains lots of useful * information about the request. * * @param response The HttpServletResponse object, * which allows the output being sent * back to be tailored. */

protected void doTestbarChart(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { OutputStream out = response.getOutputStream();

  try
  {
    String query = "SELECT * from satya";
            JDBCPieDataset dataset = new JDBCPieDataset(
                            "jdbc:mysql://localhost:3306/db_jasper",

"com.mysql.jdbc.Driver", "root", "password");

            dataset.executeQuery(query);
            JFreeChart chart = ChartFactory.createPieChart("Call

Record Report", dataset,

                    true,
                            true,true);
            PiePlot plot = (PiePlot) chart.getPlot();
            plot.setSimpleLabels(true);

try {

ChartUtilities.saveChartAsJPEG(new File("C:/piechart.jpg"), chart, 400, 300); } catch (IOException e) { System.out.println("Problem in creating chart."); } // No, no URLs

     chart.setBackgroundPaint(Color.white);

//response.setHeader("Content-Disposition", "attachment;filename=piechart.jpg"); response.setContentType("image/png"); //response.setContentType("application/octet-stream"); ChartUtilities.writeChartAsPNG(out, chart, 500, 400); } catch (Exception e) { System.out.println(e.toString()); } finally { out.close(); }

} // End Method

} // End Class


Advertisement
View Answers

May 26, 2012 at 5:55 PM


The given code is in core java. You can use it in Servlet. It display the pie chart values with percentage.

import java.awt.*;
import java.awt.event.*;
import java.awt.event.*;
import java.text.*;
import javax.swing.*;
import org.jfree.chart.*;
import org.jfree.chart.labels.StandardPieSectionLabelGenerator;
import org.jfree.chart.plot.PiePlot;
import org.jfree.data.general.*;
import org.jfree.ui.*;

import org.jfree.util.*;


public class PieChart extends ApplicationFrame {

    public PieChart(final String title) {

        super(title);
        final PieDataset dataset = createDataset(14);


        final JFreeChart chart = ChartFactory.createPieChart(
            "Pie Chart Demo ",  
            dataset,             
            false,               
            true,
            false
        );

        chart.setBackgroundPaint(new Color(222, 222, 255));
        final PiePlot plot = (PiePlot) chart.getPlot();
        plot.setBackgroundPaint(Color.white);
        plot.setLabelGenerator(new StandardPieSectionLabelGenerator(" {2}", NumberFormat.getNumberInstance(), NumberFormat.getPercentInstance()));

        final ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
        setContentPane(chartPanel);

    }
    private PieDataset createDataset(final int sections) {
        final DefaultPieDataset result = new DefaultPieDataset();
        for (int i = 0; i < sections; i++) {
            final double value = 100.0 * Math.random();
            result.setValue("" + i, value);
        }
        return result;
    }

    public static void main(final String[] args) {

        Log.getInstance().addTarget(new PrintStreamLogTarget());
        final PieChart demo = new PieChart("Pie Chart Demo");
        demo.pack();
        RefineryUtilities.centerFrameOnScreen(demo);
        demo.setVisible(true);
    }
}


Related Tutorials/Questions & Answers:
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 jfreechart.Now I need to display the values and their percentage in the sections
how to show effect (visual) on jsp page using value from database
how to show effect (visual) on jsp page using value from database  I... i want is when the value in booking status is "booked" then the pictures shown as seats should be displayed red. when the value in booking status
Advertisements
graph generation using jfreechart and retrieving values from the database
graph generation using jfreechart and retrieving values from the database ... database using prepared statement and then display the bar graph using..... Note that it is a access made database. How can I proceed ..Pls answer.Its very
how to retrieve image from mysql database using java and show it in HTML img tag ?
how to retrieve image from mysql database using java and show it in HTML img tag ?  how to retrieve image from mysql database using java and show it in HTML img tag
How to show database values into graph using jsp?
How to show database values into graph using jsp?  How to show database values into graph using jsp
How to show database values into graph using jsp?
How to show database values into graph using jsp?  How to show database values into graph using jsp
how to retrieve data from database using combobox value without using request.getParameter in jsp - JSP-Servlet
how to retrieve data from database using combobox value without using request.getParameter in jsp  Answer pl
How to show data from database in textbox in jsp
How to show data from database in textbox in jsp   How to show data from database in textbox in jsp   Here is an example that retrieve the particular record from the database and display it in textbox using JSP. <
jfreechart display from access database data.
jfreechart display from access database data.  I have made a database... to retrieve the data from the access database using prepared statement and then display the bar graph using jfreechart API .This whole retrieval and display of chart
How to retrieve data from database by using combo box value in jsp? - JSP-Servlet
How to retrieve data from database by using combo box value in jsp?  ...; } function showEmp(emp_value) { if(document.getElementById("emp_id").value...="+emp_value xmlHttp.onreadystatechange=stateChanged xmlHttp.open("GET",url
select value from autocomplete textbox using jquery in jsp from database.
select value from autocomplete textbox using jquery in jsp from database.  Hii Sir, Lots of thnx to ur reply .I went through both... of selecting value from autocomplete textbox using jquery in jsp from mysql database
select value from autocomplete textbox using jquery in jsp from database.
select value from autocomplete textbox using jquery in jsp from database. ... but was unable to find out exact way to fullfill the solution of selecting value from autocomplete textbox using jquery in jsp from mysql database. Kindly send me
jfreechart displaying chart from access database
jfreechart displaying chart from access database  I have these 2 codes. array.java----in which i retrieve the values from the database . import... javax.servlet.http.HttpServletResponse; /** * * @author AARUSHI */ class database { int roll; String
how to insert checkbox value into database using jsp
how to insert checkbox value into database using jsp  how to insert check box value to the database using jsp my code is <link href..." name="pmanager" value="Enter" ></td> <td align
how to insert checkbox value into database using jsp
how to insert checkbox value into database using jsp  How to insert check box value to the oracle database using jsp? I want to create hotel's...(); ResultSet rs=statement.executeQuery("SELECT NVL(MAX(PACK_ID),0) + 1 FROM PACKAGE
how to insert checkbox value into database using jsp
how to insert checkbox value into database using jsp  How to insert check box value to the oracle database using jsp? I want to create hotel's...=conn.createStatement(); ResultSet rs=statement.executeQuery("SELECT NVL(MAX(PACK_ID),0) + 1 FROM
how to show x axis values of timeline chart in jfreechart with particular month.
how to show x axis values of timeline chart in jfreechart with particular month.  my x-axix timeline having day of 1 month and days shows me only differently and 1 month. I want month attached with days
How to read value from xml using java?
How to read value from xml using java?  Hi All, I want to read value from following xml using java.. In <Line>,data is in format of key and value pair.. i want to read only values..could u plz help me in this?Thanks
how to show data in database ?
how to show data in database ?  how to show the data in the database to the user in the textbox so that user can modify it and save it again
JFreeChart- Display coordinate value .
JFreeChart- Display coordinate value .  How to Mark Coordinte value on top of the bar
populating textbox value from the database using onchange function,
populating textbox value from the database using onchange function,  ... dynamically from the database(mysql). after selecting the value from the dropd.... but the next textbox value is populated from database. plz help me guys
How to Autogenerate of ID from database and show on JSP page?
How to Autogenerate of ID from database and show on JSP page?  ... tasks id as primay key, I am using JSP and struts for database connectivity,Now I... entered task id,task name ,date etc properly in the database,but what and how
How to Autogenerate of ID from database and show on JSP page?
How to Autogenerate of ID from database and show on JSP page?  ... tasks id as primay key, I am using JSP and struts for database connectivity,Now I... etc properly in the database,but what and how should i make
How to Autogenerate of ID from database and show on JSP page?
How to Autogenerate of ID from database and show on JSP page?  ... tasks id as primay key, I am using JSP and struts for database connectivity,Now I... etc properly in the database,but what and how should i make
How to Autogenerate of ID from database and show on JSP page?
How to Autogenerate of ID from database and show on JSP page?  ... tasks id as primay key, I am using JSP and struts for database connectivity,Now I... etc properly in the database,but what and how should i make
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 location  Hello Sir, I am developing a demo project in which i need to display the chart in web page. I generated the chart using Jfreechart
How to delete the row from the Database by using servlet
How to delete the row from the Database by using servlet  Dear Sir...: Delete row from database using servlet   In that link solution... then the user data to be delete from the database table. Assume in Database table have
how to display a table from database using servlet
how to display a table from database using servlet  how to display a table with values from servletpage   Hi Friend, Please go through the following link: http://roseindia.net/jsp/servlet-jsp-data-list.shtml Thanks
Subtract a value in the database from java
Subtract a value in the database from java   Hi, i want to know how to subtract a value on a database. im using JDBC connection from access and i want to decrement the value of table "quantity" of 1 each time it passes a loop my
PieChart/BarGraph
PieChart/BarGraph  Hii..i have developed an application and i want to display the values from the database in the piechart/barchart but the problem is that it is taking only 5 values from database and i have 10 values in it.how
how to display data from database according to entered value in search field
how to display data from database according to entered value in search...("SELECT M.MEMBER_ID, M.FNAME,M.LNAME,M.AGE,B.HEIGHT,B.WEIGHT, B.BMI_VALUE FROM...(); System.out.println("Disconnected from database"); } catch (Exception e
How to show autocomplete textbox values on combo box option selection using database?
How to show autocomplete textbox values on combo box option selection using database?  When I select option(i.e First Year) then it will show list of student names in auto-complete text box
how to load value in dropdown list after selecting value from first dropdown list using javascript
how to load value in dropdown list after selecting value from first dropdown list using javascript  how to load value in dropdown list after selecting value from first dropdown list using javascript
how to read values from excel sheet and compare with database using jsp
how to read values from excel sheet and compare with database using jsp  hi sir i am arun how to read values from excel sheet and compare with database using jsp coding i.e, if i have 6(assetid,assetname,serialno,cubical
Update value of database using hibernate.
Update value of database using hibernate.  How to update value of database using hibernate?   Hibernate provides facility to update... as salary0_0_ from employee employee0_ where employee0_.emp_id=? Updated Description
How to insert image in sql database from user using servlet
How to insert image in sql database from user using servlet  pls tell me accept image from user and insert image in sql server 2005 database using servlet and jsp
how to store and retrieve images int and from the database using php
how to store and retrieve images int and from the database using php  please anyone can help me in storing the images and retrieve it back from the Mysql database using php
How to show multiple identicle rows from database on clicking search button to jtable
How to show multiple identicle rows from database on clicking search button...); } } }); } }   Here is a code that search the data from the database and show multiple identical rows from database on clicking search button
How to show multiple identicle rows from database on clicking search button to jtable
How to show multiple identicle rows from database on clicking search button...); } } }); } }   Here is a code that search the data from the database and show multiple identical rows from database on clicking search button
How to show multiple identicle rows from database on clicking search button to jtable
How to show multiple identicle rows from database on clicking search button...); } } }); } }   Here is a code that search the data from the database and show multiple identical rows from database on clicking search button
Create Histogram using Jfreechart
Create Histogram using Jfreechart In this section, you will learn how to create histogram using jfreechart. To create a Histogram, we have used... of ten randomly generated numbers to the dataset, using the specified number
How to Retrieve Data from the database and write into excel file using Java
How to Retrieve Data from the database and write into excel file using Java  Hi, I am trying to develop an small application where i trying to retrieve Data from the database and store the details in excel file. Please can
read value from database & alert it is available in database or not
read value from database & alert it is available in database or not  how to read value from text box and alert whether it is available in database...="text/javascript"> function check(value){ xmlHttp=GetXmlHttpObject() var
related retrieving value from oracle database
related retrieving value from oracle database  how we get the value from database in the given textbox
related retrieving value from oracle database
related retrieving value from oracle database  how we get the value from database in the given textbox
how to display values from database into table using jsp
how to display values from database into table using jsp  I want to display values from database into table based on condition in query, how... the values from database based on the bookname or authorname entered must be display
how to generate reports from oracle database using jsp and ajax code
how to generate reports from oracle database using jsp and ajax code  Hai masters i am new to this Java world. my team leader ask me to generate sales report data from oracle database to jsp page please any one know how to do
how to check username & password from database using jsp
how to check username & password from database using jsp  Hello, I have created 1 html page which contain username, password & submit button. in my oracle10G database already contain table name admin which has name, password
How to get the data from the database using Servlet or JSP program
How to get the data from the database using Servlet or JSP program  ... the problem   Get data from database using servlet Retrieve data from database using JSP Get data from database using JSP
How to show next question from database on the click of next button..(Struts & Hibernate)
How to show next question from database on the click of next button..(Struts & Hibernate)  Sir, I am facing this problem since 3 days.. I have... from "cards" table. passing parameter from viewalllists.jsp to flashPage.jsp
Advertisements
 

 

 

DMCA.com