軟件藝術思考者  
          混沌,彷徨,立志,蓄勢...
          公告
          日歷
          <2025年5月>
          27282930123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567

          導航

          隨筆分類(86)

          隨筆檔案(85)

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

           
          1.折線圖

          <%@ page contentType="text/html;charset=GBK"%>
          <%@ page import="java.awt.Color"%>
          <%@ page import = "org.jfree.chart.ChartFactory,
                            org.jfree.chart.ChartPanel,
                            org.jfree.chart.JFreeChart,
                            org.jfree.chart.DefaultOldLegend,
                            org.jfree.chart.axis.NumberAxis,
            org.jfree.chart.plot.CategoryPlot,
            org.jfree.chart.plot.PlotOrientation,
            org.jfree.chart.renderer.category.LineAndShapeRenderer,
            org.jfree.data.category.CategoryDataset,
            org.jfree.data.category.DefaultCategoryDataset,
            org.jfree.chart.servlet.ServletUtilities
          "%>
          <%@ page import="org.jfree.chart.axis.CategoryAxis"%>
          <%@ page import="org.jfree.chart.axis.CategoryLabelPositions"%>
          <%@ page import="org.jfree.data.general.DatasetUtilities"%>
          <jsp:directive.page import="org.jfree.chart.labels.StandardCategoryItemLabelGenerator"/>

          <%

          String[] rowKeys= null;//柱數據
          String[] columnKeys=null;//刻度數據

          rowKeys = new String[]{"219.146.1.196","219.146.10.105","219.146.10.116","219.146.10.73"};
          columnKeys = new String[]{"2008年7月上旬","2007-02-04"};

          double[][] data = new double[rowKeys.length][columnKeys.length];
          data = new double[][]{
            {1022.0,856.0},{676.0,13563.0},{12827.0,10576.0},{0.0,100.0} 
            };
          CategoryDataset dataset = DatasetUtilities.createCategoryDataset(rowKeys, columnKeys, data);
          JFreeChart chart = ChartFactory.createLineChart(
                     "這是測試標題...",
                      "時間",
                      "訪問量",                 // range axis label
                     dataset,                   // data
                     PlotOrientation.VERTICAL,  // orientation
                     true,                      // include legend
                     true,                      // tooltips
                     false                      // urls
                 );
          chart.setBackgroundPaint(Color.WHITE);  //-----------------------------背景色
          chart.setBorderVisible(true);  //--------------------------------------設置邊框是否可見
          chart.setBorderPaint(Color.BLUE);  //-----------------------------------設置邊框顏色setBorderVisible()必須為true

          CategoryPlot plot = chart.getCategoryPlot();
          plot.setBackgroundPaint(Color.CYAN);
          CategoryAxis domainAxis = plot.getDomainAxis();
          domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45);
                  plot.setDomainAxis(domainAxis);
                 // customise the range axis... 設置統計圖中只顯示整數
                 NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
                 rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
                 rangeAxis.setAutoRangeIncludesZero(true);
                 rangeAxis.setUpperMargin(0.20);
                 rangeAxis.setLabelAngle(Math.PI / 2.0); 
                   
                 LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();  
                 renderer.setItemLabelsVisible(true);
                 renderer.setShapesVisible(true);//series 點(即數據點)可見
                 renderer.setSeriesPaint(0, new Color(0, 0, 255));
                 renderer.setSeriesPaint(1, new Color(255, 0, 255));
                 renderer.setSeriesPaint(2, new Color(0, 255, 255));
                 renderer.setSeriesPaint(3, new Color(0,125,0));
                 renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());
              renderer.setItemLabelsVisible(true);
               
          String filename = ServletUtilities.saveChartAsPNG(chart, 850, 550, null, session);
          String graphURL = request.getContextPath() + "/servlet/DisplayChart?filename=" + filename;
          %>
          <br>
          <link href="css/default.css" rel="stylesheet" type="text/css">
          <center>
          <img src="<%= graphURL %>" width=850 height=550 border=0 usemap="#<%= filename %>">

           2.餅狀圖

          <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
          <%@ page import="java.io.FileOutputStream"%>
          <%@ page import="java.io.IOException"%>
          <%@ page import="java.io.*"%>
          <%@ page import="java.awt.Color"%>
          <%@ page import="java.awt.*"%>
          <%@ page import="java.awt.event.*"%>
          <%@ page import="javax.swing.*"%>
          <%@ page import="org.jfree.chart.*"%>
          <%@ page import="org.jfree.data.*"%>
          <%@ page import="org.jfree.data.general.*"%>
          <%@ page import="org.jfree.data.category.*"%>
          <%@ page import="org.jfree.chart.plot.PlotOrientation"%>
          <%@ page import="org.jfree.data.category.CategoryDataset"%>
          <%@ page import="org.jfree.data.category.DefaultCategoryDataset"%>
          <%@ page import="org.jfree.ui.ApplicationFrame"%>
          <%@ page import="org.jfree.chart.plot.CategoryPlot"%>
          <%@ page import="org.jfree.chart.axis.NumberAxis"%>
          <%@ page import="org.jfree.chart.renderer.category.LineAndShapeRenderer"%>
          <%@ page import="org.jfree.chart.renderer.category.*"%>
          <%@ page import="org.jfree.chart.renderer.category.LineAndShapeRenderer"%>
          <%@ page import="org.jfree.chart.plot.PiePlot"%>
          <%@page import ="org.jfree.chart.labels.StandardCategoryItemLabelGenerator"%>
          <%@page import ="org.jfree.chart.renderer.category.BarRenderer3D"%>
          <%@ page import="org.jfree.data.general.DefaultPieDataset"%>
          <%@ page import="org.jfree.chart.*"%>
          <%@ page import="org.jfree.chart.plot.*"%>
          <%@ page import="org.jfree.chart.servlet.ServletUtilities"%>
          <%@ page import="org.jfree.chart.urls.StandardPieURLGenerator"%>
          <%@ page import="org.jfree.chart.entity.StandardEntityCollection"%>
          <%
            DefaultPieDataset data = new DefaultPieDataset();
            //數據初始化
            data.setValue("高中以下",380);
            data.setValue("高中",1620);
            data.setValue("大專",6100);
            data.setValue("本科",8310);
            data.setValue("碩士",3520);
            data.setValue("博士",1900);
            
            //HttpSession session = request.getSession();
            
            PiePlot plot = new PiePlot(data);//生成一個3D餅圖
            //plot.setURLGenerator(new StandardPieURLGenerator("DegreedView.jsp"));//設定圖片鏈接
            JFreeChart chart = new JFreeChart("",JFreeChart.DEFAULT_TITLE_FONT, plot, true);
            chart.setBackgroundPaint(java.awt.Color.white);//可選,設置圖片背景色
            chart.setTitle("程序員學歷情況調查表-By Alpha");//可選,設置圖片標題
            //plot.setToolTipGenerator(new StandardPieURLGenerator());
            StandardEntityCollection sec = new StandardEntityCollection();
            ChartRenderingInfo info = new ChartRenderingInfo(sec);
            PrintWriter w = new PrintWriter(out);//輸出MAP信息
            //500是圖片長度,300是圖片高度
            //String filename = ServletUtilities.saveChartAsPNG(chart,500,300,info,session);
            String filename = ServletUtilities.saveChartAsJPEG(chart,500,300,info,session);
            ChartUtilities.writeImageMap(w,"map0",info,false);
            
            String graphURL = request.getContextPath() + "/servlet/DisplayChart?filename=" + filename;

          %>
          <img src="<%= graphURL %>" width=500 height=300 border=0 usemap="#map0">

          3.柱狀圖

          <%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
          <jsp:directive.page import="org.jfree.data.general.DatasetUtilities"/>
          <jsp:directive.page import="org.jfree.chart.JFreeChart"/>
          <jsp:directive.page import="org.jfree.chart.ChartFactory"/>
          <jsp:directive.page import="org.jfree.chart.plot.PlotOrientation"/>
          <jsp:directive.page import="java.awt.Color"/>
          <jsp:directive.page import="org.jfree.chart.plot.CategoryPlot"/>
          <jsp:directive.page import="org.jfree.chart.axis.CategoryAxis"/>
          <jsp:directive.page import="org.jfree.chart.axis.CategoryLabelPositions"/>
          <jsp:directive.page import="org.jfree.chart.axis.NumberAxis"/>
          <jsp:directive.page import="org.jfree.chart.servlet.ServletUtilities"/>
          <jsp:directive.page import="org.jfree.data.category.CategoryDataset"/>
          <jsp:directive.page import="org.jfree.chart.renderer.category.BarRenderer3D"/>
          <jsp:directive.page import="org.jfree.chart.labels.StandardCategoryItemLabelGenerator"/>
          <jsp:directive.page import="org.jfree.chart.axis.AxisLocation"/>
          <jsp:directive.page import="java.text.DecimalFormat"/>
          <%
          String[] rowInfo = new String[]{"one","two"};
          String[] colInfo = new String[]{"first","second"};
          double[][] dataInfo = new double[2][2];
          dataInfo = new double[][]{
            {1022.0,856.0},{676.0,13563.0} 
            };
          CategoryDataset data = DatasetUtilities.createCategoryDataset(rowInfo,colInfo,dataInfo);
          JFreeChart chart = ChartFactory.createBarChart3D("this is test......",
                            "row",
                            "col",
                            data,
                            PlotOrientation.VERTICAL,
                            true,false,false);
          chart.setAntiAlias(true);
          chart.setBackgroundPaint(Color.WHITE);
          chart.setBorderPaint(Color.BLACK);
          chart.setBorderVisible(true);

          //圖表區域對象,基本上這個對象決定著什么樣式的圖表,創建該對象的時候需要Axis、Renderer以及數據集對象的支持
          CategoryPlot plot = chart.getCategoryPlot();
          plot.setDomainGridlinePaint(Color.RED); //橫坐標網格線白色
          plot.setDomainGridlinesVisible(true); //可見
          plot.setBackgroundPaint(Color.CYAN);

          //用于處理圖表的兩個軸:縱軸和橫軸
          CategoryAxis axis = plot.getDomainAxis();
          axis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
          axis.setAxisLinePaint(Color.RED);
          //axis.setLabel("asdfasdfa");
          //axis.setUpperMargin(5);
          axis.setTickMarksVisible(true);
          axis.setAxisLineVisible(true);


          NumberAxis numberaxis = (NumberAxis)plot.getRangeAxis();
          numberaxis.setAutoTickUnitSelection(true);
          numberaxis.setAutoRangeIncludesZero(false);

          BarRenderer3D renderer = new BarRenderer3D();

          renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());
          renderer.setItemLabelsVisible(true);
          renderer.setBaseOutlinePaint(Color.BLACK);
          //設置 Wall 的顏色
          renderer.setWallPaint(Color.GREEN);
          //設置每種柱的顏色
          //renderer.setSeriesPaint(0, new Color(0, 0, 255));
          //renderer.setSeriesPaint(1, new Color(0, 100, 255));
          //設置平行柱之間距離
          renderer.setItemMargin(0.02);
          //顯示每個柱的數值,并修改該數值的字體屬性
          //renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());
          //renderer.setItemLabelsVisible(true);
          plot.setRenderer(renderer);

          //設置柱的透明度
          plot.setForegroundAlpha(0.8f);
          //設置地區、銷量的顯示位置
          plot.setDomainAxisLocation(AxisLocation.TOP_OR_RIGHT);
          plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);

          String filename = ServletUtilities.saveChartAsPNG(chart, 850, 550, null, session);
          String graphURL = request.getContextPath() + "/servlet/DisplayChart?filename=" + filename;
           %>

          <center>
          <img src="<%= graphURL %>" width=850 height=550 border=0 usemap="#<%= filename %>">

           

          posted on 2008-10-21 12:00 智者無疆 閱讀(751) 評論(3)  編輯  收藏 所屬分類: about java
          評論:
          • # re: 內部類的用法  智者無疆 Posted @ 2008-10-21 12:09
            package com.movo.movonet.web.interceptor;

            import java.util.Calendar;
            import java.util.Date;
            import java.util.List;
            import java.util.Map;

            import javax.servlet.http.HttpServletRequest;

            import org.apache.log4j.Logger;
            import org.omg.PortableInterceptor.ServerRequestInterceptor;

            import com.movo.movonet.GetAddress;
            import com.movo.movonet.pojo.Compass;
            import com.movo.movonet.pojo.NVisitcount;
            import com.movo.movonet.second.service.NVisitCountService;
            import com.movo.movonet.service.visitCompassService;
            import com.movo.movonet.web.BaseAction;
            import com.opensymphony.webwork.ServletActionContext;
            import com.opensymphony.webwork.dispatcher.SessionMap;
            import com.opensymphony.webwork.interceptor.ScopeInterceptor;
            import com.opensymphony.xwork.ActionContext;
            import com.opensymphony.xwork.ActionInvocation;
            import com.opensymphony.xwork.interceptor.Interceptor;
            import com.opensymphony.xwork.interceptor.PreResultListener;
            import com.opensymphony.xwork.util.OgnlValueStack;

            public class TotalVisitIntercetor extends ScopeInterceptor{
            Logger log = Logger.getLogger(TotalVisitIntercetor.class);
            private visitCompassService visitcompassService;
            private NVisitCountService visitCountService;
            private NVisitcount visitCount;
            HttpServletRequest request;
            Compass compass;
            /**
            * @return visitCount
            */
            public NVisitcount getVisitCount() {
            return visitCount;
            }

            /**
            * @param visitCount ????õ? visitCount
            */
            public void setVisitCount(NVisitcount visitCount) {
            this.visitCount = visitCount;
            }

            /**
            * @return visitCountService
            */
            public NVisitCountService getVisitCountService() {
            return visitCountService;
            }

            /**
            * @param visitCountService ????õ? visitCountService
            */
            public void setVisitCountService(NVisitCountService visitCountService) {
            this.visitCountService = visitCountService;
            }

            public void setVisitcompassService(visitCompassService visitcompassService) {
            this.visitcompassService = visitcompassService;
            }

            protected void before(ActionInvocation invocation) throws Exception {
            invocation.addPreResultListener(this);
            }

            protected void after(ActionInvocation invocation, String result) throws Exception {

            }

            public void beforeResult(ActionInvocation arg0, String arg1) {
            request = ServletActionContext.getRequest();
            compass = (Compass)ServletActionContext.getRequest().getSession().getAttribute(BaseAction.SESSION_KEY_COMPASS);
            if(compass != null){
            visitcompassService.saveVisitCompass(compass.getCompassid());
            Integer[] visitNum = visitcompassService.getVisitCompassNum(compass.getCompassid());
            BaseAction.todayVisitNum = visitNum[0].intValue();
            BaseAction.totalVisitNum = visitNum[1].intValue();
            BaseAction.totalArticleNum = visitNum[2].intValue();
            BaseAction.totalArtcommentNum = visitNum[3].intValue();
            BaseAction.totalReviewNum = visitNum[4].intValue();
            log.debug("xxxxxxxxxxxxxxxxxxx???????????"+visitcompassService);

            class innerThread implements Runnable{
            public void run() {
            HttpServletRequest request = TotalVisitIntercetor.this.request;
            Compass compass = TotalVisitIntercetor.this.compass;
            String visitIp =request.getRemoteAddr();
            String visitAddress ="";
            String sourceWebSite = request.getRemoteHost();
            String visitedHost = request.getLocalName();
            try {
            visitAddress = GetAddress.getAddressByIP(visitIp);
            } catch (Exception e) {
            e.printStackTrace();
            }
            String hql="from NVisitcount v where v.visiterIp=? and v.companyId=? and v.createtime>=?";
            Date today = new Date();
            Calendar cal = Calendar.getInstance();
            cal.setTime(today);
            cal.set(Calendar.HOUR_OF_DAY, 0);
            cal.set(Calendar.SECOND, 0);
            cal.set(Calendar.MINUTE, 0);
            today = cal.getTime();
            List<NVisitcount> li = visitCountService.find(hql,new Object[]{visitIp,compass.getCompassid(),today});
            if(li!=null&&li.size()>0){
            visitCount = li.get(0);
            visitCount.setVisitcountTotal(visitCount.getVisitcountTotal()+1);
            visitCount.setVisiterAddress(visitAddress);
            visitCountService.updateVisitCount(visitCount);
            }else{
            visitCount = new NVisitcount();
            visitCount.setCompanyId(compass.getCompassid());
            visitCount.setCreatetime(new Date());
            visitCount.setVisitcountTotal(1);
            visitCount.setVisiterAddress(visitAddress);
            visitCount.setVisiterIp(visitIp);
            visitCount.setVisitsite(visitedHost);
            visitCount.setSourceWebSite(sourceWebSite);
            visitCountService.saveVisitCount(visitCount);
            }

            }
            }

            //new Thread(new innerThread()).start();


            }
            }


            }
              回復  更多評論   

          • # re: 內部類的用法  智者無疆 Posted @ 2008-10-21 12:10
            package com.movo.movonet;
            import org.apache.commons.httpclient.HttpClient;
            import org.apache.commons.httpclient.methods.GetMethod;
            import org.apache.commons.logging.Log;
            import org.apache.commons.logging.LogFactory;

            public class GetAddress {

            public static Log log = LogFactory.getLog(GetAddress.class);
            public static String getAddressByIP(String ip) throws Exception{
            HttpClient client=new HttpClient();
            GetMethod loginMethod=new GetMethod("http://www.123cha.com/ip/?q="+ip);
            loginMethod.addRequestHeader("Content-Type", "text/html; charset=GBK");
            client.executeMethod(loginMethod);
            byte[] back = loginMethod.getResponseBody();
            String metter = new String(back,"gbk");
            String []addressBy=SystemConfig.getInstance().getConfiguration().getStringArray("sys.ipaddress");
            String begin1="參考數據一",begin2="參考數據二",begin3="本站主數據";
            String address="";
            if(metter.indexOf(begin2)>0){
            address = metter.substring(metter.indexOf(begin2)+19);
            }
            else if(metter.indexOf(begin3)>0){
            address = metter.substring(metter.indexOf(begin3)+19);
            }else {
            address = metter.substring(metter.indexOf(begin1)+19);
            }
            address = address.substring(0, address.indexOf("</li>"));
            String add[] = address.split("&nbsp;");
            if(add.length>=3){
            return add[0].trim()+add[1].trim().replace("&nbsp;", "");
            }else if(add.length==2){
            return add[0].replace("&nbsp;", "");
            }else {

            return address.replace("&nbsp;", "");
            }

            }
            public static void main(String args[]){
            try{
            getAddressByIP("120.7.188.144");

            }catch(Exception e){
            e.printStackTrace();
            }
            }


            }
              回復  更多評論   

          • # re: 幾種報表圖的畫法[未登錄]  追夢人 Posted @ 2008-12-12 14:02
            我把你的例子弄過去試。。可是org.jfree.chart.DefaultOldLegend, 報錯。。請幫忙。。謝了。
              回復  更多評論   

           
          Copyright © 智者無疆 Powered by: 博客園 模板提供:滬江博客


             觀音菩薩贊

          主站蜘蛛池模板: 福建省| 太白县| 抚宁县| 翁牛特旗| 龙海市| 连南| 康保县| 洪江市| 宁安市| 南江县| 合作市| 深水埗区| 历史| 禄丰县| 南昌市| 抚松县| 陆良县| 耒阳市| 义乌市| 镇安县| 龙井市| 榆社县| 衡阳县| 久治县| 盱眙县| 武冈市| 囊谦县| 长海县| 双鸭山市| 梁河县| 中西区| 民勤县| 龙游县| 昆山市| 清远市| 罗田县| 南陵县| 顺平县| 临汾市| 礼泉县| 镇平县|