Package org.apache.struts2.dispatcher
Class ChartResult
java.lang.Object
org.apache.struts2.result.StrutsResultSupport
org.apache.struts2.dispatcher.ChartResult
- All Implemented Interfaces:
- Serializable,- Result,- StrutsStatics
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:
- value - the name of the JFreeChart object on the ValueStack, defaults to 'chart'.
- type - the render type for this chart. Can be jpg (or jpeg) or png. Defaults to png.
- width (required) - the width (in pixels) of the rendered chart.
- height (required) - the height (in pixels) of the rendered chart.
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:
- 
Field SummaryFields inherited from class org.apache.struts2.result.StrutsResultSupportDEFAULT_PARAM, DEFAULT_URL_ENCODING, parseLocationFields inherited from interface org.apache.struts2.StrutsStaticsACTION_MAPPING, HTTP_REQUEST, HTTP_RESPONSE, PAGE_CONTEXT, SERVLET_CONTEXT, SERVLET_DISPATCHER, STRUTS_ACTION_TAG_INVOCATION
- 
Constructor SummaryConstructors
- 
Method SummaryMethods inherited from class org.apache.struts2.result.StrutsResultSupportconditionalParse, conditionalParseCollection, execute, getLastFinalLocation, getLocation, setEncode, setLocation, setParse
- 
Constructor Details- 
ChartResultpublic ChartResult()
- 
ChartResult
 
- 
- 
Method Details- 
getHeight
- 
setHeight
- 
getWidth
- 
setWidth
- 
getType
- 
setType
- 
getValue
- 
setValue
- 
getChartpublic org.jfree.chart.JFreeChart getChart()
- 
setChartpublic void setChart(org.jfree.chart.JFreeChart chart) 
- 
doExecuteExecutes the result. Writes the given chart as a PNG or JPG to the servlet output stream.- Specified by:
- doExecutein class- StrutsResultSupport
- Parameters:
- invocation- an encapsulation of the action execution state.
- Throws:
- Exception- if an error occurs when creating or writing the chart to the servlet output stream.
 
 
-