Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.struts2.dispatcher
Class ChartResult

    java.lang.Object
      org.apache.struts2.dispatcher.StrutsResultSupport
          org.apache.struts2.dispatcher.ChartResult

All Implemented Interfaces:
  com.opensymphony.xwork2.Result, Serializable, StrutsStatics

    public class ChartResult

extends 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:

- 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:
  Serialized Form

Field Summary

Fields inherited from class org.apache.struts2.dispatcher.StrutsResultSupport
`DEFAULT_PARAM, DEFAULT_URL_ENCODING`

Fields inherited from interface org.apache.struts2.StrutsStatics
`HTTP_REQUEST, HTTP_RESPONSE, PAGE_CONTEXT, SERVLET_CONTEXT, SERVLET_DISPATCHER, STRUTS_ACTION_TAG_INVOCATION, STRUTS_PORTLET_CONTEXT`

Constructor Summary
`ChartResult()`
`ChartResult(org.jfree.chart.JFreeChart chart, String height, String width)`

Method Summary
`void` | `doExecute(String finalLocation, com.opensymphony.xwork2.ActionInvocation invocation)` Executes the result.
`org.jfree.chart.JFreeChart` | `getChart()`
`String` | `getHeight()`
`String` | `getType()`
`String` | `getValue()`
`String` | `getWidth()`
`void` | `setChart(org.jfree.chart.JFreeChart chart)`
`void` | `setHeight(String height)`
`void` | `setType(String type)`
`void` | `setValue(String value)`
`void` | `setWidth(String width)`

Methods inherited from class org.apache.struts2.dispatcher.StrutsResultSupport
`conditionalParse, conditionalParseCollection, 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,
                       String height,
                       String width)

Method Detail

### getHeight

    public String getHeight()

### setHeight

    public void setHeight(String height)

### getWidth

    public String getWidth()

### setWidth

    public void setWidth(String width)

### getType

    public String getType()

### setType

    public void setType(String type)

### getValue

    public String getValue()

### setValue

    public void setValue(String value)

### getChart

    public org.jfree.chart.JFreeChart getChart()

### setChart

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

### doExecute

    public void doExecute(String finalLocation,
                          com.opensymphony.xwork2.ActionInvocation invocation)
                   throws Exception

  Executes the result. Writes the given chart as a PNG or JPG to the servlet output stream.

  Specified by:
    `doExecute` in 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.

Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2000–2017 Apache Software Foundation. All rights reserved.