org.apache.struts2.dispatcher
Class ChartResult

java.lang.Object
  extended by org.apache.struts2.dispatcher.StrutsResultSupport
      extended by org.apache.struts2.dispatcher.ChartResult
All Implemented Interfaces:
com.opensymphony.xwork2.Result, java.io.Serializable, org.apache.struts2.StrutsStatics

public class ChartResult
extends org.apache.struts2.dispatcher.StrutsResultSupport

A custom Result type for chart data. Built on top of JFreeChart. When executed this Result will write the given chart as a PNG or JPG to the servlet output stream.

This result type takes the following parameters:

Example:


 public class ExampleChartAction extends ActionSupport {

            private JFreeChart chart;

            public String execute() throws Exception {
                    // chart creation logic...
                    XYSeries dataSeries = new XYSeries(new Integer(1)); // pass a key for this serie
                    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 NumberAxis("Moderated Marks");

                    // set my chart variable
                    chart =
                            new JFreeChart( "Moderation Function", JFreeChart.DEFAULT_TITLE_FONT,
                                    new XYPlot( xyDataset, xAxis, yAxis, new StandardXYItemRenderer(StandardXYItemRenderer.LINES)),
                                    false);
                    chart.setBackgroundPaint(java.awt.Color.white);

                    return SUCCESS;
            }
 
      // this method will get called if we specify <param name="value">chart</param>
            public JFreeChart getChart() {
                    return chart;
            }
  }

 <result name="success" type="chart">
   <param name="value">chart</param>
   <param name="type">png</param>
   <param name="width">640</param>
   <param name="height">480</param>
 </result>
 

See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.apache.struts2.dispatcher.StrutsResultSupport
DEFAULT_PARAM
 
Fields inherited from interface org.apache.struts2.StrutsStatics
HTTP_REQUEST, HTTP_RESPONSE, PAGE_CONTEXT, SERVLET_CONTEXT, SERVLET_DISPATCHER, STRUTS_PORTLET_CONTEXT
 
Constructor Summary
ChartResult()
           
ChartResult(org.jfree.chart.JFreeChart chart, java.lang.String height, java.lang.String width)
           
 
Method Summary
 void doExecute(java.lang.String finalLocation, com.opensymphony.xwork2.ActionInvocation invocation)
          Executes the result.
 org.jfree.chart.JFreeChart getChart()
           
 java.lang.String getHeight()
           
 java.lang.String getType()
           
 java.lang.String getValue()
           
 java.lang.String getWidth()
           
 void setChart(org.jfree.chart.JFreeChart chart)
           
 void setHeight(java.lang.String height)
           
 void setType(java.lang.String type)
           
 void setValue(java.lang.String value)
           
 void setWidth(java.lang.String width)
           
 
Methods inherited from class org.apache.struts2.dispatcher.StrutsResultSupport
conditionalParse, execute, getLastFinalLocation, getLocation, setEncode, setLocation, setParse
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ChartResult

public ChartResult()

ChartResult

public ChartResult(org.jfree.chart.JFreeChart chart,
                   java.lang.String height,
                   java.lang.String width)
Method Detail

getHeight

public java.lang.String getHeight()

setHeight

public void setHeight(java.lang.String height)

getWidth

public java.lang.String getWidth()

setWidth

public void setWidth(java.lang.String width)

getType

public java.lang.String getType()

setType

public void setType(java.lang.String type)

getValue

public java.lang.String getValue()

setValue

public void setValue(java.lang.String value)

getChart

public org.jfree.chart.JFreeChart getChart()

setChart

public void setChart(org.jfree.chart.JFreeChart chart)

doExecute

public void doExecute(java.lang.String finalLocation,
                      com.opensymphony.xwork2.ActionInvocation invocation)
               throws java.lang.Exception
Executes the result. Writes the given chart as a PNG or JPG to the servlet output stream.

Specified by:
doExecute in class org.apache.struts2.dispatcher.StrutsResultSupport
Parameters:
invocation - an encapsulation of the action execution state.
Throws:
java.lang.Exception - if an error occurs when creating or writing the chart to the servlet output stream.


Copyright © 2000-2009 Apache Software Foundation. All Rights Reserved.