锘??xml version="1.0" encoding="utf-8" standalone="yes"?>欧美日韩123,亚洲综合二区,亚洲v日本v欧美v久久精品http://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;
聽聽 }
}



]]>
主站蜘蛛池模板: 二连浩特市| 临猗县| 阳东县| 启东市| 朝阳区| 两当县| 武隆县| 林甸县| 曲麻莱县| 福海县| 大姚县| 揭西县| 陆河县| 凤凰县| 华安县| 尚义县| 岫岩| 天台县| 文成县| 平山县| 固始县| 克山县| 贞丰县| 阜宁县| 阿克陶县| 大田县| 江北区| 内黄县| 理塘县| 大洼县| 柞水县| 大庆市| 安图县| 资阳市| 德昌县| 汉川市| 连江县| 漳平市| 天津市| 淮北市| 高邑县|