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

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

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

    不急不徐,持之以恒。

    http://blog.gopersist.com/

      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
      24 隨筆 :: 0 文章 :: 52 評論 :: 0 Trackbacks
    準備以下開源項目:
    1. Struts 2.1.6
    2. Open Flash Chart 2 Version 2 Lug Wyrm Charmer (28th, July 2009)
    3. jofc2,這東西不知道是沒做好還是什么意思,好像和ofc2不怎么匹配,最好下源碼,有什么問題直接改。
    4. log4j

    用eclipse新建動態網站,取名OFC2Demo,將Struts2 lib目錄下commons-fileupload-1.2.1.jar、commons-logging-1.0.4.jar、freemarker-2.3.13.jar、ognl-2.6.11.jar、struts2-core-2.1.6.jar、xstream-1.3.1.jar和xwork-2.1.2.jar、log4j.jar復制到WebContent\lib目錄下。

    使用svn下載jofc2源碼,http://jofc2.googlecode.com/svn/trunk/,將下載后的src目錄下的jofc2整個目錄和下級內容全部復制到項目src目錄下。

    在web.xml中加入struts2攔截器
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
      
    <display-name>OFC2Demo</display-name>

      
    <filter>
        
    <filter-name>struts2</filter-name>
        
    <filter-class>
          org.apache.struts2.dispatcher.FilterDispatcher
        
    </filter-class>
      
    </filter>

      
    <filter-mapping>
        
    <filter-name>struts2</filter-name>
        
    <url-pattern>/*</url-pattern>
      
    </filter-mapping>

      
    <welcome-file-list>
        
    <welcome-file>index.html</welcome-file>
        
    <welcome-file>index.htm</welcome-file>
        
    <welcome-file>index.jsp</welcome-file>
        
    <welcome-file>default.html</welcome-file>
        
    <welcome-file>default.htm</welcome-file>
        
    <welcome-file>default.jsp</welcome-file>
      
    </welcome-file-list>
    </web-app>

    在返回jofc2生成Open Flash Chart數據時,本來想用jsonplugin插件,但發現序列化jofc2的Chart對象時,許多元素名稱和Chart.toString()不同,這使得Open Flash Chart解析數據時不認識。所以需增加一個Struts2自定義Result Type,步驟如下:
    新建類,OFC2Plugin
    package com.xy.strutsplugin;

    import java.io.IOException;
    import java.io.PrintWriter;

    import javax.servlet.http.HttpServletResponse;

    import jofc2.model.Chart;

    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
    import org.apache.struts2.StrutsStatics;

    import com.opensymphony.xwork2.ActionContext;
    import com.opensymphony.xwork2.ActionInvocation;
    import com.opensymphony.xwork2.Result;
    import com.opensymphony.xwork2.util.ValueStack;

    public class OFC2Result implements Result {
        
    private static final long serialVersionUID = 6881760833309063964L;
        
    private static final Log log = LogFactory.getLog(OFC2Result.class);

        
    public void execute(ActionInvocation invocation) throws Exception {
            ActionContext actionContext 
    = invocation.getInvocationContext();
            HttpServletResponse response 
    = (HttpServletResponse) actionContext
                    .get(StrutsStatics.HTTP_RESPONSE);
            
            
    try {
                ValueStack stack 
    = invocation.getStack();
                Chart chart 
    = (Chart)stack.findValue("ofcChart");
                
                response.setContentType(
    "application/json-rpc;charset=utf-8");
                response.setHeader(
    "Cache-Control""no-cache");
                response.setHeader(
    "Expires""0");
                response.setHeader(
    "Pragma""No-cache");
                
                PrintWriter out 
    = response.getWriter();
                log.debug(chart.toString());
                out.print(chart.toString());
            } 
    catch (IOException exception) {
                log.error(exception.getMessage(), exception);
                
    throw exception;
            }
        }
    }
    在src下新建struts-plugin.xml
    <?xml version="1.0" encoding="UTF-8" ?>

    <!DOCTYPE struts PUBLIC
            
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
            
    "http://struts.apache.org/dtds/struts-2.0.dtd">

    <struts>
        
    <package name="ofc2-default" extends="struts-default">
            
    <result-types>
                
    <result-type name="ofc2" class="com.xy.strutsplugin.OFC2Result"/>
            
    </result-types>
        
    </package>
    </struts>

    配置log4j,以查看json輸出信息。
    在src下增加兩個文件
    commons-logging.properties
    ## set Log as Log4j
    org.apache.commons.logging.Log
    =org.apache.commons.logging.impl.Log4JLogger
    log4j.properties
    # This is the configuring for logging displayed in the Application Server
    log4j.rootCategory
    =DEBUG,stdout

    #stdout configure
    log4j.appender.stdout
    =org.apache.log4j.ConsoleAppender
    log4j.appender.stdout.layout
    =org.apache.log4j.PatternLayout
    log4j.appender.stdout.layout.ConversionPattern
    = %%p [%c] - <%m>%n

    ##
    log4j.logger.com.xy.strutsplugin.OFC2Result=DEBUG

    好了,現在將ofc所需的包添加到項目中
    在WebContent目錄下添加文件夾ofc2,將open-flash-chart-2-Lug-Wyrm-Charmer目錄下的open-flash-chart.swf和js目錄復制到新建的ofc2目錄下。

    演示Line Chart
    在Action層增加類LineAction
    package com.xy.action;

    import java.text.DateFormat;
    import java.util.ArrayList;
    import java.util.Date;
    import java.util.List;
    import java.util.Locale;

    import jofc2.model.Chart;
    import jofc2.model.elements.LineChart;
    import jofc2.model.axis.YAxis;
    import jofc2.model.Text;

    import com.opensymphony.xwork2.ActionSupport;

    public class LineAction extends ActionSupport{
        
    private static final long serialVersionUID = -5759373192727732648L;
        
        
    private Chart ofcChart;
        
    public Chart getOfcChart() {
            
    return ofcChart;
        }
        
        
    public String dot(){
            List
    <LineChart.Dot> data1=new ArrayList<LineChart.Dot>()
                    , data2
    =new ArrayList<LineChart.Dot>()
                    , data3
    =new ArrayList<LineChart.Dot>();
            
    for(double i=0;i<6.2;i+=0.2){
                
    // line 1 dot
                LineChart.Dot dot1 = new LineChart.Dot(Math.sin(i)*1.9+10);
                dot1.setDotSize(
    5);            // 點大小
                dot1.setColour("#f00000");    // 設置點顏色
                data1.add(dot1);
                
                
    // line 2 dot
                LineChart.Dot dot2 = new LineChart.Dot(Math.sin(i)*1.9+7);
                dot2.setDotSize(
    3);
                dot2.setHaloSize(
    1);        // 點外空白大小
                dot2.setColour("#3D5C56");
                data2.add(dot2);
                
                
    // line 3 dot
                LineChart.Dot dot3 = new LineChart.Dot(Math.sin(i)*1.9+4);
                dot3.setDotSize(
    4);
                dot3.setHaloSize(
    2);
                data3.add(dot3);
            }
            
            Date date 
    = new Date();
            Locale locale 
    = new Locale("zh","CN");
            DateFormat dateFormat 
    = DateFormat.getDateInstance(DateFormat.FULL, locale);
            
            
    // line 1
            LineChart line1 = new LineChart();
            line1.setDotStyle(
    new LineChart.Style(LineChart.Style.Type.DOT));
            line1.setWidth(
    1);            // 線寬
            line1.addDots(data1);        // 增加數據
            
            
    // line 2
            LineChart line2 = new LineChart();
            line2.setDotStyle(
    new LineChart.Style(LineChart.Style.Type.DOT));
            line2.setColour(
    "#3D5C56");
            line2.setWidth(
    2);
            line2.addDots(data2);
            
            
    // line3
            LineChart line3 = new LineChart();
            line3.setDotStyle(
    new LineChart.Style(LineChart.Style.Type.DOT));
            line3.setWidth(
    6);
            line3.addDots(data3);
            
            YAxis y 
    = new YAxis();
            y.setRange(
    0155);        // 設置Y柚范圍,參數依次為最小值、最大值、間隔

            ofcChart 
    = new Chart();
            ofcChart.setTitle(
    new Text(dateFormat.format(date)));    // 設置標題
            ofcChart.addElements(line1);                            // 增加線到圖表
            ofcChart.addElements(line2);
            ofcChart.addElements(line3);
            ofcChart.setYAxis(y);                                    
    // 設置Y柚
            
            
    return SUCCESS;
        }
    }

    增加struts配置文件
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE struts PUBLIC
            "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
            "http://struts.apache.org/dtds/struts-2.0.dtd"
    >

    <struts>
        
    <package name="ofc2" extends="ofc2-default">
           
    <action name="line" class="com.xy.action.LineAction">
             
    <result type="ofc2"/>
           
    </action>
        
    </package>
    </struts>

    在WebContent目錄下增加line目錄,目錄下增加dot.html,對應官方示例Line Dot,dot.html內容如下:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Line Dot</title>

    <script type="text/javascript" src="../jquery/jquery.js"></script>
    <script type="text/javascript" src="../ofc2/js/swfobject.js"></script>

    <script type="text/javascript" language="javascript">
        $(document).ready(
    function(){
            swfobject.embedSWF(
    "../ofc2/open-flash-chart.swf"
                        
    "chart""550""300""9.0.0",
                        
    "expressInstall.swf",
                        {
    "data-file":"line!dot"});
        });
    </script> 
    </head>
    <body>
        
    <div id="chart"></div>
    </body>
    </html>
    這里用到了一點jquery的東西,請把jquery的包增加到相應目錄下。

    運行Tomcat,瀏覽器輸入http://localhost:8080/OFC2Demo/line/dot.html,出下如下圖表



    posted on 2010-01-19 13:42 老林 閱讀(5541) 評論(9)  編輯  收藏 所屬分類: 報表開發

    評論

    # re: 用Struts2生成Open Flash Chart 2圖表數據 2010-01-20 01:18 芬達
    很好 很牛逼

    http://www.yaopinwang.org/sitemap.html  回復  更多評論
      

    # re: 用Struts2生成Open Flash Chart 2圖表數據 2010-01-20 09:17 咖啡妝
    穩定嗎 看是很不錯 配合json應該不錯  回復  更多評論
      

    # re: 用Struts2生成Open Flash Chart 2圖表數據 2010-01-22 09:53 leekiang
    這與struts2沒有關系吧  回復  更多評論
      

    # re: 用Struts2生成Open Flash Chart 2圖表數據 2010-08-16 10:07 宋學孟
    你好,我想問一下  回復  更多評論
      

    # re: 用Struts2生成Open Flash Chart 2圖表數據 2010-08-16 10:08 宋學孟
    line2.setDotStyle(new LineChart.Style(LineChart.Style.Type.DOT));
    這一句代碼是您自己寫的嗎?我看源代碼里沒有啊  回復  更多評論
      

    # re: 用Struts2生成Open Flash Chart 2圖表數據 2010-08-26 09:34 收拾
    老兄 那個數據不匹配的問題你怎么處理的哦,處理了嗎  回復  更多評論
      

    # re: 用Struts2生成Open Flash Chart 2圖表數據 2011-05-12 11:52 lies
    在把項目傳上來的話會更好!~  回復  更多評論
      

    # re: 用Struts2生成Open Flash Chart 2圖表數據 2012-02-01 11:15 兔斯基想敲代碼了
    OFC2Result 看著有些復雜
    上面讓我用這個畫些圖表分析數據,nnd我們用的是velocity+springmvc
    雖說都是mvc,但還是希望能找到一個用springmvc實現功能的例子,還是感謝博主了。  回復  更多評論
      

    # re: 用Struts2生成Open Flash Chart 2圖表數據 2012-02-29 11:08 11
    line2.setDotStyle(new LineChart.Style(LineChart.Style.Type.DOT));
    這一句代碼是您自己寫的嗎?我看源代碼里沒有啊  回復  更多評論
      

    主站蜘蛛池模板: 日韩免费观看一区| 免费h黄肉动漫在线观看| 99久久综合精品免费| 亚洲国产品综合人成综合网站| 99re8这里有精品热视频免费| 亚洲高清无在码在线电影不卡| 日韩免费高清视频| 中文字幕久精品免费视频| 亚洲乱码在线观看| 亚洲色中文字幕无码AV| 欧美a级成人网站免费| 亚洲日本人成中文字幕| 久久亚洲中文字幕精品一区四| 最近2022中文字幕免费视频| 深夜a级毛片免费视频| 亚洲日产2021三区| 亚洲伊人久久综合影院| 国产黄在线播放免费观看| 亚洲喷奶水中文字幕电影| 国产aⅴ无码专区亚洲av麻豆 | 亚洲一区爱区精品无码| 91精品免费在线观看| 黄视频在线观看免费| 亚洲AV无码片一区二区三区| 亚洲人成网www| 亚洲国产a级视频| 成人免费看片又大又黄| 午夜免费啪视频在线观看| 日韩精品免费一线在线观看| 亚洲妇女熟BBW| 久久久无码精品亚洲日韩蜜臀浪潮 | 亚洲免费在线播放| 亚洲日本一区二区一本一道| 成人免费毛片观看| 最近2022中文字幕免费视频| 日韩精品无码免费专区午夜不卡| 亚洲av片在线观看| 亚洲一本到无码av中文字幕| 亚洲成aⅴ人片在线观| 久久亚洲一区二区| 亚洲中文无码永久免费|