org.apache.struts2.dispatcher
Class ChartResult

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

public class ChartResult
extends java.lang.Object
implements com.opensymphony.xwork2.Result

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

Constructor Summary
ChartResult()
           
ChartResult(org.jfree.chart.JFreeChart chart, int height, int width)
           
 
Method Summary
 void execute(com.opensymphony.xwork2.ActionInvocation invocation)
          Executes the result.
 org.jfree.chart.JFreeChart getChart()
           
 java.lang.Integer getHeight()
           
 java.lang.String getType()
           
 java.lang.String getValue()
           
 java.lang.Integer getWidth()
           
 void setChart(org.jfree.chart.JFreeChart chart)
           
 void setHeight(java.lang.Integer height)
           
 void setType(java.lang.String type)
           
 void setValue(java.lang.String value)
           
 void setWidth(java.lang.Integer width)
           
 
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,
                   int height,
                   int width)
Method Detail

getHeight

public java.lang.Integer getHeight()

setHeight

public void setHeight(java.lang.Integer height)

getWidth

public java.lang.Integer getWidth()

setWidth

public void setWidth(java.lang.Integer 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)

execute

public void execute(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:
execute in interface com.opensymphony.xwork2.Result
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.