当前位置: 代码迷 >> JavaScript >> 高分!如何让FusionChartsFree画出来的图显示在表格里
  详细解决方案

高分!如何让FusionChartsFree画出来的图显示在表格里

热度:259   发布时间:2012-04-05 12:42:40.0
高分求助!!怎么让FusionChartsFree画出来的图显示在表格里
我把代码贴出来麻烦各位高手帮忙看下
1、最终显示页面test.jsp,这个页面是经过精简的,其实有更多代码,但与本问题无关
HTML code

<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'test.jsp' starting page</title>
    
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->

  </head>
  
  <body>
    <table width="350px" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#bdd5e0"  class="ntable">
          <tr height="45px">
            <td width="38%" align="center" bgcolor="#e6effb"><strong>柱状图</strong></td>
          </tr> 
           <tr height="200px">
             <td bgcolor="#FFFFFF" class="tdl">
                <jsp:include page="includes/chart.jsp" flush="true"> 
                <jsp:param name="phone_id" value="127011" /> 
              </jsp:include>
            </td>                 
                  </tr>
            </table>  
  </body>
</html>



2、test.jsp中include的chart.jsp
HTML code

<%@ page language="java"%>
<%@ page import="java.sql.*"%> 
<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<HTML>
    <HEAD>
        <TITLE>FusionCharts Free - Database And Connection Class Example</TITLE>
        <SCRIPT LANGUAGE="Javascript" SRC="../FusionCharts/FusionCharts.js"></SCRIPT>
        <style type="text/css">
            <!--
            body {
                font-family: Arial, Helvetica, sans-serif;
                font-size: 12px;
            }
            .text{
                font-family: Arial, Helvetica, sans-serif;
                font-size: 12px;
            }
            -->
            </style>
    </HEAD>
    <BODY>
        <CENTER>
            <%
                int pid = Integer.parseInt(request.getParameter("phone_id"));
                //int pid=127011;
                Class.forName("com.mysql.jdbc.Driver").newInstance();
                Connection con=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/rv_mining","root","123123");
                Statement st1=null;
                ResultSet rs1=null;
                String strXML="";
                String strXML1="";
                strXML = "<graph xAxisname='参数列表' yAxisname='用户倾向值' hovercapbg='DEDEBE' hovercapborder='889E6D'"+
                " rotateNames='0' yAxisMaxValue='40' numdivlines='5' divLineColor='CCCCCC' divLineAlpha='80'"+
                " decimalPrecision='0' showAlternateHGridColor='1' AlternateHGridAlpha='30' AlternateHGridColor='CCCCCC'>";
                strXML += "<categories font='Arial' fontSize='11' fontColor='000000'>"+
                           "<category name='屏幕'/>  <category name='系统性能' />"+ 
                           "<category name='外观及附件' />  <category name='通话及音效' /> "+
                           "<category name='待机' /> <category name='娱乐' />"+
                           "<category name='总体评价' /> </categories>";
                strXML += "<dataset seriesname='正面评价' color='56B9F9'>";
                strXML1 = "<dataset seriesname='负面评价' color='FDC12E'>";
                try {            
                    int P = 0;
                    int N = 0;
                    st1=con.createStatement();
                    rs1 = st1.executeQuery("select * from rvm_chart where phone_id="+pid+"");
                    while(rs1.next()){
                        P = rs1.getInt("P_value");
                        N = rs1.getInt("N_value");
                        strXML += " <set value='"+P+"' /> ";
                        strXML1 += "<set value='"+N+"' /> ";
                    }
                    rs1.close();
                    st1.close();
                    con.close();
                }catch(SQLException e) {
                    e.printStackTrace();
                }
                strXML1 += "</dataset>";
                strXML += "</dataset>"+strXML1+"</graph>";
            %> 
            <jsp:include page="FusionChartsRenderer.jsp" flush="true"> 
                        <jsp:param name="chartSWF" value="../FusionCharts/FCF_MSColumn2D.swf" /> 
                        <jsp:param name="strURL" value="" /> 
                        <jsp:param name="strXML" value="<%=strXML %>" /> 
                        <jsp:param name="chartId" value="UsersTrend" /> 
                        <jsp:param name="chartWidth" value="300" /> 
                        <jsp:param name="chartHeight" value="210" /> 
                        <jsp:param name="debugMode" value="false" />     
                        <jsp:param name="registerWithJS" value="false" />                         
            </jsp:include>
        </CENTER>
    </BODY>
</HTML>