⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pie3d_jsp.java

📁 基于jfreechart组件的矢量图绘制
💻 JAVA
字号:
package org.apache.jsp;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import org.jfree.data.DefaultPieDataset;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.ChartFactory;
import java.awt.Font;
import org.jfree.chart.plot.Pie3DPlot;
import org.jfree.chart.ChartRenderingInfo;
import org.jfree.chart.servlet.ServletUtilities;
import org.jfree.chart.urls.StandardPieURLGenerator;
import org.jfree.chart.entity.StandardEntityCollection;

public final class Pie3D_jsp extends org.apache.jasper.runtime.HttpJspBase
    implements org.apache.jasper.runtime.JspSourceDependent {

  private static java.util.Vector _jspx_dependants;

  public java.util.List getDependants() {
    return _jspx_dependants;
  }

  public void _jspService(HttpServletRequest request, HttpServletResponse response)
        throws java.io.IOException, ServletException {

    JspFactory _jspxFactory = null;
    PageContext pageContext = null;
    HttpSession session = null;
    ServletContext application = null;
    ServletConfig config = null;
    JspWriter out = null;
    Object page = this;
    JspWriter _jspx_out = null;
    PageContext _jspx_page_context = null;


    try {
      _jspxFactory = JspFactory.getDefaultFactory();
      response.setContentType("text/html;charset=GBK");
      pageContext = _jspxFactory.getPageContext(this, request, response,
      			null, true, 8192, true);
      _jspx_page_context = pageContext;
      application = pageContext.getServletContext();
      config = pageContext.getServletConfig();
      session = pageContext.getSession();
      out = pageContext.getOut();
      _jspx_out = out;

      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
 request.setCharacterEncoding("gb2312");
      out.write('\r');
      out.write('\n');


//try{

int NUMBER=Integer.parseInt(request.getParameter("Number"));
String[] NAME3D=new String[NUMBER];
float[] VALUE3D=new float[NUMBER];
String title=request.getParameter("Title");


   NAME3D[0]=request.getParameter("3dname0");
 
   VALUE3D[0]=Float.parseFloat(request.getParameter("3dvalue0"));
   NAME3D[1]=request.getParameter("3dname1");
 
   VALUE3D[1]=Float.parseFloat(request.getParameter("3dvalue1"));

   NAME3D[2]=request.getParameter("3dname2");
   VALUE3D[2]=Float.parseFloat(request.getParameter("3dvalue2"));

   NAME3D[3]=request.getParameter("3dname3");
   VALUE3D[3]=Float.parseFloat(request.getParameter("3dvalue3"));
   
 
 
   DefaultPieDataset data = new DefaultPieDataset();
   for(int i=0;i<NUMBER;i++){
     data.setValue(NAME3D[i],VALUE3D[i]);
     }
//}catch(Exception e){}


JFreeChart chart = ChartFactory.createPie3DChart(title,data, true,true, true);
chart.setBackgroundPaint(java.awt.Color.white);//可选,设置图片背
//chart.setTitle(new TextTitle("www.SenTom.net ",new Font("隶书", Font.ITALIC, 12)));//可选,设置图片标题


Pie3DPlot pie3D = (Pie3DPlot)chart.getPlot();//PiePlot plot = new PiePlot(data);

ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
//500是图片长度,300是图片高度

String filename = ServletUtilities.saveChartAsJPEG(chart, 500, 300, info, session);
//String fileName = "d:/test/" + filename;

String graphURL = request.getContextPath()+ "/DisplayChart?filename=" + filename; 

//FileOutputStream fos_jpg = null;
//fos_jpg = new FileOutputStream("D:\\"+filename);
//ChartUtilities.writeChartAsJPEG(fos_jpg,100,chart,400,300,null);


      out.write("\r\n");
      out.write("<HTML>\r\n");
      out.write("<HEAD>\r\n");
      out.write("       <TITLE>Draw your chart</TITLE>\r\n");
      out.write("</HEAD>\r\n");
      out.write("<BODY>\r\n");
      out.write("\r\n");
      out.write("<P ALIGN=\"CENTER\">\r\n");
      out.write("       <img src=\"");
      out.print( graphURL );
      out.write("\" width=500 height=300 border=0 usemap=\"#");
      out.print( filename );
      out.write("\">\r\n");
      out.write("</P>\r\n");
      out.write("\r\n");
      out.write("<table align=\"center\" width=50% border=\"1\" bgcolor=\"yellow\">\r\n");
      out.write("<tr><th>序号</th><th>名称</th><th>数值</th></th>\r\n");
 for(int i=0;i<NUMBER;i++){
      out.write("\r\n");
      out.write("<tr> <th>");
      out.print(i);
      out.write("</th>\r\n");
      out.write("     <th>");
      out.print(NAME3D[i]);
      out.write("</th>\r\n");
      out.write("     <th>");
      out.print(VALUE3D[i]);
      out.write("</th>\r\n");
      out.write("</tr>\r\n");
}
      out.write("\r\n");
      out.write("\r\n");
      out.write("</table>\r\n");
      out.write("\r\n");
      out.write("</BODY>\r\n");
      out.write("</HTML>\r\n");
      out.write("\r\n");
    } catch (Throwable t) {
      if (!(t instanceof SkipPageException)){
        out = _jspx_out;
        if (out != null && out.getBufferSize() != 0)
          out.clearBuffer();
        if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
      }
    } finally {
      if (_jspxFactory != null) _jspxFactory.releasePageContext(_jspx_page_context);
    }
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -