Read the data from the database and integrate it into a 3D pie chart to show details in jsp. 3 djsp

Source: Internet
Author: User

Read the data from the database and integrate it into a 3D pie chart to show details in jsp. 3 djsp

Preface

This article mainly introduces the content about reading database data, integrating it into a 3D pie chart and displaying it in jsp, and sharing it for your reference, let's take a look at the detailed introduction:

The method is as follows:

First, I will write the pie chart generation method into a PieChar. java class independently. The detailed code is as follows: (the database needs to be built by myself, if necessary)

Import java. io. IOException; import java. SQL. SQLException; import org. jfree. chart. chartFactory; import org. jfree. chart. JFreeChart; import org. jfree. data. general. defaultPieDataset; public class PieChart {public JFreeChart chart = null; public PieChart () throws IOException, SQLException {defapipiedataset data = getDataset (); chart = ChartFactory. createPieChart3D ("commodity quantity pie chart", data, true, false, false); // create a pie chart} // custom method, generate pie chart dataset private static defapipiedataset getDataset () throws SQLException {defapipiedataset dabaset = new partition (); ConnDB conn = new ConnDB (); String SQL = "select p_type, count (p_type) as p_type_count from product group by (p_type) "; conn. rs = conn. doQuery (SQL); // read database data and generate a dataset while (conn. rs. next () {dabaset. setValue (conn. rs. getString ("p_type"), conn. rs. getInt ("p_type_count");} return dabaset ;}}

Then, call the java class in the jsp file. The detailed code is as follows:

<Jsp: useBean id = "pies" class = "bean. pieChart "> </jsp: useBean> <body> <% String filename = ServletUtilities. saveChartAsPNG (pies. chart, 500,300, null, session); // generate the image path String graphURL = request. getContextPath () + "/servlet/DisplayChart? Filename = "+ filename; // The complete path of the generated image in the project: System. out. println (graphURL); %> <div align = "center">  </div> </body>

This is not enough. You must configure the web. xml file to display the image. The detailed configuration is as follows:

<servlet>  <servlet-name>DisplayChart</servlet-name>  <servlet-class>org.jfree.chart.servlet.DisplayChart</servlet-class></servlet><servlet-mapping>  <servlet-name>DisplayChart</servlet-name>  <url-pattern>/servlet/DisplayChart</url-pattern></servlet-mapping>

Complete servlet ing.

The final result is as follows:

Summary

The above is all the content of this article. I hope the content of this article will help you in your study or work. If you have any questions, please leave a message to us. Thank you for your support.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.