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:
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>
DEFAULT_PARAM, DEFAULT_URL_ENCODING, parseLocation
HTTP_REQUEST, HTTP_RESPONSE, PAGE_CONTEXT, SERVLET_CONTEXT, SERVLET_DISPATCHER, STRUTS_ACTION_TAG_INVOCATION, STRUTS_PORTLET_CONTEXT
Constructor and Description |
---|
ChartResult() |
ChartResult(org.jfree.chart.JFreeChart chart,
String height,
String width) |
Modifier and Type | Method and Description |
---|---|
void |
doExecute(String finalLocation,
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) |
conditionalParse, conditionalParseCollection, execute, getLastFinalLocation, getLocation, setEncode, setLocation, setParse
public String getHeight()
public void setHeight(String height)
public String getWidth()
public void setWidth(String width)
public String getType()
public void setType(String type)
public String getValue()
public void setValue(String value)
public org.jfree.chart.JFreeChart getChart()
public void setChart(org.jfree.chart.JFreeChart chart)
public void doExecute(String finalLocation, ActionInvocation invocation) throws Exception
doExecute
in class StrutsResultSupport
invocation
- an encapsulation of the action execution state.Exception
- if an error occurs when creating or writing the chart to the servlet output stream.Copyright © 2000–2020 Apache Software Foundation. All rights reserved.