锘??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲天堂男人天堂,欧美精品一区二,久久久久久久久久久99999http://www.aygfsteel.com/javaora/category/9825.htmlzh-cnTue, 27 Feb 2007 18:25:47 GMTTue, 27 Feb 2007 18:25:47 GMT60JFreechartResulthttp://www.aygfsteel.com/javaora/archive/2006/04/11/40420.htmljava涓栫晫鐣呰皥java涓栫晫鐣呰皥Tue, 11 Apr 2006 03:55:00 GMThttp://www.aygfsteel.com/javaora/archive/2006/04/11/40420.htmlhttp://www.aygfsteel.com/javaora/comments/40420.htmlhttp://www.aygfsteel.com/javaora/archive/2006/04/11/40420.html#Feedback0http://www.aygfsteel.com/javaora/comments/commentRss/40420.htmlhttp://www.aygfsteel.com/javaora/services/trackbacks/40420.html Intro

I am rendering a chart to the output stream. Instead of streaming it directly to the response.out, I create a ChartResult , and let webwork do the chaining for me.

I generate the chart in one class, and I render it out in another class, efftectively decoupling the view from the actions. You can easily render it out to file or some view other than a web response.out if you wish.

Configuration
xwork.xml -result-types definitions
<result-types>
聽聽 <result-type name="chart" class="myapp.webwork.extensions.chartResult"/>
</result-types>
xwork.xml -action definitions
<action name="viewModerationChart" class="myapp.webwork.actions.ViewModerationChartAction">
聽聽 <result name="success" type="chart">
聽聽聽聽聽 <param name="width">400</param>
聽聽聽聽聽 <param name="height">300</param>
聽聽 </result>
</action>

Source Codes
My result class search for a "chart" in the ValueStack and renders it out...

public class ChartResult implements聽 Result{
聽聽 private int width;
聽聽 private int height;
聽聽 public void execute(ActionInvocation invocation)throws Exception{
聽聽聽聽聽聽 JFreeChart chart = (JFreeChart)invocation.getStack().findValue("chart");
聽聽聽聽聽聽 HttpServeletResponse response = ServeletActionContext.getResponse();
聽聽聽聽聽聽 OutputStream os = response.getOutputStream();
聽聽聽聽聽聽 ChartUtilities.writeChartAsPNG(os,chart,width,height);
聽聽聽聽聽聽 os.flush();
聽聽 }
聽聽聽聽聽
聽聽 public void setHeight(int height){
聽聽聽聽 this.height=height;
聽聽 }
聽聽
聽聽 public void setWidth(int width){
聽聽聽聽 this.width=width;
聽聽 }
}

public class ViewModerationChartAction extends ActionSupport{
聽聽 private JFreeChart chart;
聽聽
聽聽 public String execute() throws Exception{
聽聽聽聽聽 //chart creation logic ...
聽聽聽聽聽 XYSeries dataSeries = new XYSeries(new Integer(1));
聽聽聽聽聽 for(int i=0;i<=100;i++){
聽聽聽聽聽聽聽聽 dataSeries.add(i,RandomUtils.nextInt());
聽聽聽聽聽 }
聽聽聽聽聽
聽聽聽聽聽 XYSeriesCollection xyDataset = new XYSeriesCollection(dataSeries);
聽聽聽聽聽 ValueAxis xAxis = new NumberAxis("Raw Marks");
聽聽聽聽聽 ValueAxis yAxis = new NumberXxis("Moderated Marks");
聽聽聽聽聽
聽聽聽聽聽 chart = new JFreeChart(
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 "Moderation Function",
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 JFreeChart.DEFAULT_TITLE_FONT,
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 new XYPlot(
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 xyDataset,
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 xAxis,
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 yXis,
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 new
聽聽聽聽聽聽聽聽聽聽 StandardXYItemRenderer(StandardXYItemRender.LINES),
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 false聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 );
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 ...
聽聽聽聽聽 )
聽聽 }
聽聽
聽聽 public JFreeChart getChart(){
聽聽聽聽聽 return chart;
聽聽 }
}



]]>
主站蜘蛛池模板: 敦煌市| 比如县| 财经| 永和县| 内江市| 永靖县| 隆子县| 房产| 宁晋县| 海口市| 虞城县| 安义县| 沾益县| 茶陵县| 友谊县| 郑州市| 梅河口市| 油尖旺区| 永安市| 紫金县| 商都县| 双桥区| 西乌| 五大连池市| 手游| 南通市| 临邑县| 罗源县| 木兰县| 泽州县| 布拖县| 湖南省| 灌南县| 平泉县| 安塞县| 彭州市| 齐齐哈尔市| 侯马市| 淮安市| 贵定县| 阳原县|