Kimi's NutShell

我荒废的今日,正是昨日殒身之人祈求的明日

BlogJava 新随笔 管理
  141 Posts :: 0 Stories :: 75 Comments :: 0 Trackbacks

.JSPX:
<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="1.2"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:af="http://xmlns.oracle.com/adf/faces"
          xmlns:afh="http://xmlns.oracle.com/adf/faces/html"
          xmlns:graph="/webapp/graph.tld">
  <jsp:directive.page contentType="text/html;charset=UTF-8"/>
  <jsp:directive.page import="Bar,java.io.*,org.jfree.chart.*,org.jfree.chart.servlet.*,java.util.*"/>
  <html>
    <body><!--jsp:scriptlet>
  Bar chart = new Bar();
  String filename = chart.generateChart("", session, new PrintWriter(out), 75, 45);
  String graphURL = request.getContextPath() + "/servlet/DisplayChart?filename=" +filename;
   </jsp:scriptlet-->
     <!--h:graphicImage url="/img/acmecenter.jpg" height="200"
                                     width="190"
                                     /-->
                                    
<f:view>
        <afh:html>
      <f:loadBundle basename="com.primesuccess.portal.resources.UIResources"
                        var="res"/>
          <afh:head title="#{res['home.title']}"/>
          <afh:body inlineStyle="margin:0.0pt; padding:0.0pt;">
            <af:form>
              <af:panelPage>
                <f:facet name="branding">
                  <af:objectImage source="/img/SRBranding.gif"/>
                </f:facet>
                <f:facet name="menuGlobal">
                  <h:panelGroup>
                    <af:menuButtons>
                      <h:outputFormat value="#{res['portal.connectedUser']}"
                                      escape="false" rendered="true">
                        <f:param value="#{account.username}"/>
                      </h:outputFormat>
                      <af:objectSpacer width="140" height="10"/>
                      <af:commandMenuItem text="#{res['portal.logout']}"
                                          action="logout" immediate="true"
                                          icon="/img/logout.gif"/>
                    </af:menuButtons>
                  </h:panelGroup>
                </f:facet>
                <f:facet name="menu1">
                  <af:menuTabs var="menuTab" value="#{account.model}">
                    <f:facet name="nodeStamp">
                      <!--af:commandMenuItem text="#{menuTab.label}"
                                      action="#{menuTab.getOutcome}"
                                      rendered="#{menuTab.shown and menuTab.type=='default'}"
                                      disabled="#{menuTab.readOnly}"/-->
                      <af:commandMenuItem text="#{menuTab.label}"
                                          action="#{menuTab.getOutcome}"
                                          rendered="#{menuTab.shown and menuTab.type=='default'}"
                                          disabled="#{menuTab.readOnly}"/>
                    </f:facet>
                  </af:menuTabs>
                </f:facet>
                <f:facet name="messages">
                  <af:messages message="aaa" globalOnly="true"/>
                </f:facet>
                <f:facet name="appCopyright">
                  <af:outputText value="#{res['portal.copyright']}"/>
                </f:facet>
                <af:panelHorizontal halign="center">
                  <af:objectImage source="/img/acmecenter.jpg" align="middle"/>
                </af:panelHorizontal>
              </af:panelPage>
              <h:graphicImage url="#{chart.graphURL}" height="175" width="300"
                              usemap="#{chart.filename}" ismap="false"/>
                                <!--h:graphicImage url="/img/acmecenter.jpg" height="200"
                                     width="190"
                                     /-->
            </af:form>
          </afh:body>
        </afh:html>
      </f:view></body>
  </html>
</jsp:root>

Model:
 // FrontEnd Plus GUI for JAD
 // DeCompiled : Chart.class

 

 import java.io.PrintWriter;
import java.io.Writer;

import java.text.NumberFormat;
 import javax.servlet.http.HttpSession;
 
 import javax.servlet.http.HttpServletRequest;


import oracle.adf.share.http.Http21Util;

import org.jfree.chart.*;
 import org.jfree.chart.axis.NumberAxis;
 import org.jfree.chart.entity.StandardEntityCollection;
 import org.jfree.chart.imagemap.ImageMapUtilities;
 import org.jfree.chart.plot.PlotOrientation;
 import org.jfree.chart.plot.XYPlot;
 import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
 import org.jfree.chart.servlet.ServletUtilities;
 import org.jfree.data.xy.*;

 public class Bar
 {
 String filename=new String();
 String graphURL=new String();
    HttpSession session;
    HttpServletRequest request;
    PrintWriter pw;
 

     public Bar()
     {
     }

     private static XYDataset createDataset1()
     {
         XYSeries xyseries = new XYSeries("Lot Count");
         xyseries.add(0.0D, 0.0D);
         xyseries.add(1.0D, 10D);
         xyseries.add(2D, 20D);
         xyseries.add(3D, 30D);
         xyseries.add(4D, 50D);
         xyseries.add(5D, 32D);
         xyseries.add(6D, 15D);
         xyseries.add(7D, 5D);
         xyseries.add(8D, 20D);
         xyseries.add(9D, 35D);
         xyseries.add(10D, 80D);
         XYSeries xyseries1 = new XYSeries("Series 2");
         xyseries1.add(0.0D, 0.0D);
         xyseries1.add(1.0D, 10D);
         xyseries1.add(2D, 18D);
         xyseries1.add(3D, 22D);
         xyseries1.add(4D, 35D);
         xyseries1.add(5D, 50D);
         xyseries1.add(6D, 55D);
         xyseries1.add(7D, 66D);
         xyseries1.add(8D, 78D);
         xyseries1.add(9D, 95D);
         xyseries1.add(10D, 100D);
         XYSeriesCollection xyseriescollection = new XYSeriesCollection();
         xyseriescollection.addSeries(xyseries);
         xyseriescollection.addSeries(xyseries1);
         return xyseriescollection;
     }

     private static JFreeChart createChart(String targetUrl)
     {
         XYDataset xydataset = createDataset1();
         JFreeChart jfreechart = ChartFactory.createXYLineChart("Fab1", "MCT", "Lot Count", xydataset, PlotOrientation.VERTICAL, true, true, false);
         XYPlot xyplot = jfreechart.getXYPlot();
         NumberAxis numberaxis = new NumberAxis("Line2");
         numberaxis.setAutoRangeIncludesZero(false);
         numberaxis.setAutoRangeMinimumSize(1.0D);
         numberaxis.setNumberFormatOverride(NumberFormat.getPercentInstance());
         xyplot.setRangeAxis(1, numberaxis);
         xyplot.mapDatasetToRangeAxis(1, 1);
         NumberAxis numberaxis1 = new NumberAxis("MCT");
         numberaxis1.setAutoRangeIncludesZero(false);
         numberaxis1.setAutoRangeMinimumSize(1.0D);
         xyplot.setDomainAxis(numberaxis1);
         XYLineAndShapeRenderer xylineandshaperenderer = new XYLineAndShapeRenderer();
         xylineandshaperenderer.setSeriesLinesVisible(0, false);
         xyplot.setRenderer(xylineandshaperenderer);
         return jfreechart;
     }

     public String generateChart(String targetUrl, HttpSession session,PrintWriter pw, int w, int h)
     {
         JFreeChart chart = createChart(targetUrl);
         ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
         String filename=new String();
         try
         {
             filename = ServletUtilities.saveChartAsPNG(chart,w,h,info,session);
             ImageMapUtilities.writeImageMap(pw, filename, info);
             pw.flush();
         }
         catch(Exception e)
         {
             e.printStackTrace();
            
           
         }
        
         return filename;
     }

    public void setFilename(String filename) {
        this.filename = filename;
    }

    public String getFilename() {
        return this.generateChart("", session, pw, 750, 450);
    }

    public void setGraphURL(String graphURL) {
        this.graphURL = graphURL;
    }

    public String getGraphURL() {
    System.out.println("FILENAME:"+this.getFilename());
    String s="" + "/servlet/DisplayChart?filename=" +this.getFilename();
  
        return s;
    }
   
}

动态则DAO连接数据库

posted on 2006-04-11 14:11 Kimi 阅读(461) 评论(0)  编辑  收藏 所属分类: Java

只有注册用户登录后才能发表评论。


网站导航: