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
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


vikas pandey
how to show value and percentage in piechart sections from database using jfreechart
1 Answer(s)      2 years and 5 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
how to show image as a link which path coming from database
how to show image as a link which path coming from database   iam not getting proper answer for it. I am using netbeans .the url coming instring from database ,want to display as image on jsp . please help 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
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
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
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 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 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 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
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 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 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
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 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
 

 

 

DMCA.com