<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    我的漫漫程序之旅

    專注于JavaWeb開發(fā)
    隨筆 - 39, 文章 - 310, 評論 - 411, 引用 - 0
    數(shù)據(jù)加載中……

    Flash圖表(FusionChartsV3)的簡單應用

    項目中需要用到報表,發(fā)現(xiàn)這個Flash做的工具很好用~
    效果漂亮,且支持多達40多種報表。
    看圖:

    簡單說下這個東東在jsp環(huán)境下的應用.
    java代碼:
    package com.eline.epicc.utils;

    import java.io.IOException;

    import javax.servlet.http.HttpServletResponse;

    /**
     * 報表生成公共類(創(chuàng)建FusionCharts<flash cool>)
     * 
     * 
    @author zdw
     * 
     
    */

    public class ChartUtils
    {
        
    /**
         * 對Url數(shù)據(jù)轉碼的方法
         * 
    @param strDataURL   - chart的數(shù)據(jù)url
         * 
    @param addNoCacheStr - 非緩存字符串
         * 
    @return
         
    */


        
    public String encodeDataURL(String strDataURL, String addNoCacheStr,
                HttpServletResponse response)
        
    {
            String encodedURL 
    = strDataURL;
            
    if (addNoCacheStr.equals("true"))
            
    {
                java.util.Calendar nowCal 
    = java.util.Calendar.getInstance();
                java.util.Date now 
    = nowCal.getTime();
                java.text.SimpleDateFormat sdf 
    = new java.text.SimpleDateFormat(
                        
    "MM/dd/yyyy HH_mm_ss a");
                String strNow 
    = sdf.format(now);
                
    if (strDataURL.indexOf("?"> 0)
                
    {
                    encodedURL 
    = strDataURL + "&FCCurrTime=" + strNow;
                }

                
    else
                
    {
                    strDataURL 
    = strDataURL + "?FCCurrTime=" + strNow;
                }

                encodedURL 
    = response.encodeURL(strDataURL);

            }

            
    return encodedURL;
        }


        
    /**
         * 用HTML+JavaScript創(chuàng)建FusionCharts對象(用此方式需要導入FusionCharts.js文件)
         * 
    @param chartSWF -
         *            flash文件的位置,即chart圖表類型
         * 
    @param strURL - xml數(shù)據(jù)源
         * 
    @param strXML - 字符流
         * 
    @param chartId - chart對象在HTML中的唯一標識
         * 
    @param chartWidth -  flash chart 的寬度(單位px)
         * 
    @param chartHeight -  flash chart 的高度(單位px)
         * 
    @param debugMode - 是否開啟chart 調試模式
         * 
    @param registerWithJS - 是否注冊自己
         
    */

        
    public static String createChart(String chartSWF, String strURL,
                String strXML, String chartId, 
    int chartWidth, int chartHeight,
                
    boolean debugMode, boolean registerWithJS)
        
    {
            StringBuffer strBuf 
    = new StringBuffer();
            strBuf.append(
    "<!--START Script Block for Chart -->\n");
            strBuf.append(
    "\t\t<div id='" + chartId + "Div' align='center'>\n");
            strBuf.append(
    "\t\t\t\tChart.\n");
            strBuf.append(
    "\t\t</div>\n");
            strBuf.append(
    "\t\t<script type='text/javascript'>\n");
            Boolean registerWithJSBool 
    = new Boolean(registerWithJS);
            Boolean debugModeBool 
    = new Boolean(debugMode);
            
    int regWithJSInt = boolToNum(registerWithJSBool);
            
    int debugModeInt = boolToNum(debugModeBool);

            strBuf.append(
    "\t\t\t\tvar chart_" + chartId + " = new FusionCharts('"
                    
    + chartSWF + "', '" + chartId + "', '" + chartWidth + "', '"
                    
    + chartHeight + "', '" + debugModeInt + "', '" + regWithJSInt
                    
    + "');\n");
            
    if (strXML.equals(""))
            
    {
                strBuf.append(
    "\t\t\t\t//Set the dataURL of the chart\n");
                strBuf.append(
    "\t\t\t\tchart_" + chartId + ".setDataURL(\""
                        + strURL + "\");\n");
            }

            
    else
            
    {
                strBuf
                        .append(
    "\t\t\t\t//Provide entire XML data using dataXML method\n");
                strBuf.append(
    "\t\t\t\tchart_" + chartId + ".setDataXML(\""
                        + strXML + "\");\n");
            }

            strBuf.append(
    "\t\t\t\t//Finally, render the chart.\n");
            strBuf.append(
    "\t\t\t\tchart_" + chartId + ".render(\"" + chartId
                    + "Div\");\n");
            strBuf.append("\t\t</script>\n");
            strBuf.append(
    "\t\t<!--END Script Block for Chart-->\n");
            
    return strBuf.substring(0);
        }


        
    /**
         * 創(chuàng)建swf charts對象(HTML)
         * 
         * 
    @param chartSWF -
         *            flash文件的位置,即chart圖表類型
         * 
         * 
    @param strURL -
         *            xml數(shù)據(jù)源
         * 
    @param strXML -
         *            If you intend to use dataXML method for this chart, pass the
         *            XML data as this parameter. Else, set it to "" (in case of
         *            dataURL method)
         * 
    @param chartId -
         *            chart對象在HTML中的唯一標識
         * 
    @param chartWidth -
         *            flash chart 的寬度(單位px)
         * 
    @param chartHeight -
         *            flash chart 的高度(單位px)
         * 
    @param debugMode -
         *            是否開啟chart 調試模式
         
    */


        
    public static String createChartHTML(String chartSWF, String strURL,
                String strXML, String chartId, 
    int chartWidth, int chartHeight,
                
    boolean debugMode)
        
    {
            String strFlashVars 
    = "";
            Boolean debugModeBool 
    = new Boolean(debugMode);

            
    if (strXML.equals(""))
            
    {
                strFlashVars 
    = "chartWidth=" + chartWidth + "&chartHeight="
                        
    + chartHeight + "&debugMode=" + boolToNum(debugModeBool)
                        
    + "&dataURL=" + strURL + "";
            }

            
    else
            
    {
                strFlashVars 
    = "chartWidth=" + chartWidth + "&chartHeight="
                        
    + chartHeight + "&debugMode=" + boolToNum(debugModeBool)
                        
    + "&dataXML=" + strXML + "";
            }

            StringBuffer strBuf 
    = new StringBuffer();
            
    // 開始輸出Object chart
            strBuf.append("\t\t<!--START Code Block for Chart-->\n");
            strBuf
                    .append(
    "\t\t\t\t<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='"
                            
    + chartWidth
                            
    + "' height='"
                            
    + chartHeight
                            
    + "' id='"
                            
    + chartId + "'>\n");
            strBuf
                    .append(
    "\t\t\t\t    <param name='allowScriptAccess' value='always' />\n");
            strBuf.append(
    "\t\t\t\t    <param name='movie' value='" + chartSWF
                    
    + "'/>\n");
            strBuf.append(
    "\t\t\t\t<param name='FlashVars' value=\"" + strFlashVars
                    + "\" />\n");
            strBuf.append("\t\t\t\t    <param name='quality' value='high' />\n");
            strBuf
                    .append(
    "\t\t\t\t<embed src='"
                            
    + chartSWF
                            
    + "' FlashVars=\""
                            + strFlashVars
                            
    + "\" quality='high' width='"
                            + chartWidth
                            
    + "' height='"
                            
    + chartHeight
                            
    + "' name='"
                            
    + chartId
                            
    + "' allowScriptAccess='always' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />\n");
            strBuf.append(
    "\t\t</object>\n");
            strBuf.append(
    "\t\t<!--END Code Block for Chart-->\n");
            
    return strBuf.substring(0);
        }


        
    /**
         * 提供快速輸出Chart的便捷方法(基于字符流的方式)
         * 
         * 
    @param chartSWF :
         *            flash文件的位置,即chart圖表類型
         * 
    @param strXml :
         *            xml文件流(string格式)
         * 
    @param chartId :
         *            chart對象在HTML中的唯一標識
         * 
    @param chartWidth :
         *            flash chart 的寬度(單位px)
         * 
    @param chartHeight:
         *            flash chart 的高度(單位px)
         * 
    @param response :
         *            reponse對象
         
    */

        
    public static void outChartHTML(String chartSWF, String strXml,
                String chartId, 
    int chartWidth, int chartHeight,
                HttpServletResponse response)
        
    {
            String str 
    = createChartHTML(chartSWF, "", strXml, chartId, chartWidth,
                    chartHeight, 
    false);
            
    try
            
    {
                response.getWriter().write(str);
            }
     catch (IOException e)
            
    {
                e.printStackTrace();
            }

        }


        
    /**
         * 提供快速輸出Chart的便捷方法(基于xml文件的方式)
         * 
         * 
    @param chartSWF :
         *            flash文件的位置,即chart圖表類型
         * 
    @param strURL :
         *            xml數(shù)據(jù)源(路徑格式)
         * 
    @param chartId :
         *            chart對象在HTML中的唯一標識
         * 
    @param chartWidth :
         *            flash chart 的寬度(單位px)
         * 
    @param chartHeight:
         *            flash chart 的高度(單位px)
         * 
    @param response :
         *            reponse對象
         
    */

        
    public static void outChartSourceHTML(String chartSWF, String strURL,
                String chartId, 
    int chartWidth, int chartHeight,
                HttpServletResponse response)
        
    {
            String str 
    = createChartHTML(chartSWF, strURL, "", chartId, chartWidth,
                    chartHeight, 
    false);
            
    try
            
    {
                response.getWriter().write(str);
            }
     catch (IOException e)
            
    {
                e.printStackTrace();
            }

        }


        
    /**
         * bollean轉換為int
         
    */

        
    private static int boolToNum(Boolean bool)
        
    {
            
    int num = 0;
            
    if (bool.booleanValue())
            
    {
                num 
    = 1;
            }

            
    return num;
        }

    }


    jsp:
    <%@ page language="java" pageEncoding="UTF-8"%>
    <%@page import="com.eline.epicc.utils.ChartUtils"%>
    <%@page import="com.eline.epicc.utils.Constants"%>
    <HTML>
        
    <HEAD>
            
    <TITLE>FusionCharts - Simple Column 3D Chart</TITLE>
        
    </HEAD>
        
    <BODY>
            
    <%
                
    //文件源示例
                ChartUtils.outChartSourceHTML(
    "common/charts/Column3D.swf",
                        
    "data.xml""myFirst"600300, response);
                
    String[][] arrData = new String[6][2];
                
    //產品名字
                arrData[
    0][0= "Product A";
                arrData[
    1][0= "Product B";
                arrData[
    2][0= "Product C";
                arrData[
    3][0= "Product D";
                arrData[
    4][0= "Product E";
                arrData[
    5][0= "Product F";

                arrData[
    0][1= "567500";
                arrData[
    1][1= "815300";
                arrData[
    2][1= "556800";
                arrData[
    3][1= "734500";
                arrData[
    4][1= "676800";
                arrData[
    5][1= "648500";
                
    //Now, we need to convert this data into XML. We convert using string concatenation.
                
    String strXML;
                
    int i = 0;
                strXML 
    = "<chart caption='Sales by Product' numberPrefix='$' formatNumberScale='0'>";
                
    for (i = 0; i < arrData.length; i++)
                {
                    strXML 
    = strXML + "<set label='" + arrData[i][0]
                            
    + "'       value='" + arrData[i][1+ "' />";
                }
                strXML 
    = strXML + "</chart>";
                
    //String字符串流示例
                ChartUtils.outChartHTML(Constants.COLUMN3D, strXML,
                        
    "myFirst"600300, response);
            
    %>
        
    </BODY>
    </HTML>


    xml數(shù)據(jù)文件:

    <?xml version="1.0" encoding="UTF-8"?>
    <chart caption='Monthly Unit Sales' xAxisName='Month' yAxisName='Units' showValues='0' formatNumberScale='0' showBorder='1'>
        
    <set label='Jan' value='462' />
        
    <set label='Feb' value='857' />
        
    <set label='Mar' value='671' />
        
    <set label='Apr' value='494' />
        
    <set label='May' value='761' />
        
    <set label='Jun' value='960' />
        
    <set label='Jul' value='629' />
        
    <set label='Aug' value='622' />
        
    <set label='Sep' value='376' />
        
    <set label='Oct' value='494' />
        
    <set label='Nov' value='761' />
        
    <set label='Dec' value='960' />
    </chart>

    當然FusionCharts支持很多種編程語言,具體你可以看附件的CHM.
    附上破解版的下載和我做的Chm幫助文檔。
    下載

    posted on 2008-11-06 16:14 々上善若水々 閱讀(6226) 評論(22)  編輯  收藏

    評論

    # re: Flash圖表(FusionChartsV3)的簡單應用   回復  更多評論   

    下載需要密碼,密碼是多少呢?
    2008-11-06 16:50 | tp

    # re: Flash圖表(FusionChartsV3)的簡單應用   回復  更多評論   

    我知道了,用納米盤客戶端下載就要密碼。ie下載不需要
    2008-11-06 16:52 | tp

    # re: Flash圖表(FusionChartsV3)的簡單應用   回復  更多評論   

    謝謝。正需要呢。
    不過是否可以在項目中用破解版,這個還真不好取舍。
    2008-11-06 17:18 | IceRao

    # re: Flash圖表(FusionChartsV3)的簡單應用   回復  更多評論   

    to:@IceRao
    哈哈,我們公司用的就是破解版~
    2008-11-06 17:21 | 々上善若水々

    # re: Flash圖表(FusionChartsV3)的簡單應用   回復  更多評論   

    好東西 謝謝分享
    2008-11-06 17:38 | lvq810

    # re: Flash圖表(FusionChartsV3)的簡單應用   回復  更多評論   

    有free版本的卻要用破解版,有必要嗎?我覺得free版本已經(jīng)基本夠用了,連程序員自己都支持盜版,這年頭。。。
    2008-11-06 18:00 | EricFan

    # re: Flash圖表(FusionChartsV3)的簡單應用   回復  更多評論   

    @EricFan

    破解的支持的多,還有就是效果好一些。對于外國的軟件,堅決用破解,因為在清朝的時候我們已經(jīng)付過錢了。
    2008-11-06 21:24 | supercrsky

    # re: Flash圖表(FusionChartsV3)的簡單應用 [未登錄]  回復  更多評論   

    慎用盜版
    2008-11-06 21:35 | xZeus

    # re: Flash圖表(FusionChartsV3)的簡單應用 [未登錄]  回復  更多評論   

    好東西,有機會要用一下.
    2008-11-06 23:27 | 的的

    # re: Flash圖表(FusionChartsV3)的簡單應用 [未登錄]  回復  更多評論   

    謝謝。正需要呢。
    2008-11-07 08:42 | gg

    # re: Flash圖表(FusionChartsV3)的簡單應用   回復  更多評論   

    使用FLEX,交互性更好吧
    2008-11-07 16:39 | dfjnn

    # re: Flash圖表(FusionChartsV3)的簡單應用   回復  更多評論   

    不能下載
    2008-11-07 22:32 | 扭曲的鉛筆

    # re: Flash圖表(FusionChartsV3)的簡單應用   回復  更多評論   

    不錯的工具,不知FREE版是不是夠用,做程式的還是要支持正版才好。
    2008-11-08 13:55 | Vincent.Yu

    # re: Flash圖表(FusionChartsV3)的簡單應用   回復  更多評論   

    Constants 這個類在哪里啊。怎么沒有呢
    2008-11-11 10:37 | pikenlike

    # re: Flash圖表(FusionChartsV3)的簡單應用   回復  更多評論   

    能留下你的qq或者是msn么?
    共同研究
    2008-11-11 11:37 | pikenlike

    # re: Flash圖表(FusionChartsV3)的簡單應用   回復  更多評論   

    @pikenlike
    Constants.COLUMN3D 是我自己寫的常量類,你只需要把你的swf文件的路徑傳進去就行了。
    2008-11-12 08:47 | 々上善若水々

    # re: Flash圖表(FusionChartsV3)的簡單應用   回復  更多評論   

    請問一下樓主,如何讓FusionCharts生成的圖表在網(wǎng)頁上循環(huán)播放啊,謝謝!!!
    2008-11-20 17:34 |

    # re: Flash圖表(FusionChartsV3)的簡單應用   回復  更多評論   

    不明白你說的什么意思,不斷刷新Chart自己?
    2008-11-21 18:44 | 々上善若水々

    # re: Flash圖表(FusionChartsV3)的簡單應用   回復  更多評論   

    就是說網(wǎng)頁上有多個圖表,當頁面加載時所有動畫效果已經(jīng)完成,下邊的圖表無法看到動畫的效果,只是個最終的結果,如果有循環(huán)控制的話就可以看到下邊的圖表時仍然可以看到動畫效果,也相當于不斷刷新自己吧!謝謝
    2008-11-22 10:18 |

    # re:ALL  回復  更多評論   

    諸位大蝦,請問這個案例是否從數(shù)據(jù)庫中取值,然后通過XML加載到swf中?
    有人用asp或者.net做過嗎?
    2009-03-24 08:43 | 網(wǎng)名很土

    # re: Flash圖表(FusionChartsV3)的簡單應用   回復  更多評論   

    @網(wǎng)名很土
    當然可以,chm中有例子
    2009-03-26 14:09 | 々上善若水々

    # re: Flash圖表(FusionChartsV3)的簡單應用   回復  更多評論   

    @々上善若水々
    大哥。。。貌似chm是英文版的。。。
    不過還是感謝您的解答,謝謝啦,我會常來的。
    2009-03-26 16:12 | 網(wǎng)名很土

    只有注冊用戶登錄后才能發(fā)表評論。


    網(wǎng)站導航:
     
    主站蜘蛛池模板: 色吊丝性永久免费看码 | 亚洲国产aⅴ成人精品无吗| 久久亚洲AV成人无码电影| 亚洲国产成人久久综合一| 亚洲av日韩av无码| 亚洲黄色免费网站| 亚洲精品在线播放| 国产99在线|亚洲| 亚洲AV无码男人的天堂| 国产成人亚洲综合在线| 日韩大片在线永久免费观看网站| 深夜A级毛片视频免费| 丰满妇女做a级毛片免费观看| 一级毛片视频免费| 国产色爽免费无码视频| 免费观看久久精彩视频| 最近2022中文字幕免费视频| 免费看污成人午夜网站| 大学生美女毛片免费视频| 国产在线a不卡免费视频| 国产成人亚洲综合| 久久久久亚洲AV成人无码 | 在线视频免费国产成人| 又大又粗又爽a级毛片免费看| 亚洲男人在线无码视频| 亚洲欧洲∨国产一区二区三区| 亚洲五月激情综合图片区| 亚洲av乱码一区二区三区| 亚洲国产成人AV网站| 成人无码视频97免费| 亚洲一区二区三区免费观看| 女人张开腿等男人桶免费视频| 全亚洲最新黄色特级网站| 亚洲av无码专区国产乱码在线观看 | 最近中文字幕mv免费高清在线| 在线看片免费不卡人成视频| 热99re久久免费视精品频软件| 亚洲人成无码网站久久99热国产| 久久久综合亚洲色一区二区三区| 国产成人精品日本亚洲18图| 免费视频成人国产精品网站 |