JFreeChart Plugin

Usage

To use the plugin, have your Struts configuration package extend the jfreechart-default package, which provides the chart result type. Next, use it as a result in an action:

Chart example in struts.xml
 
  1. <action name="viewModerationChart" class="myapp.actions.ViewModerationChartAction">
  2.   <result name="success" type="chart">
  3.     <param name="width">400</param>
  4.     <param name="height">300</param> 
  5.   </result>
  6. </action>

In your Action class, provide a getChart() method that returns the chart to be rendered. This method will be called by the chart result.

Example

Struts Action that provides a chart
  1. public class ViewModerationChartAction extends ActionSupport {
  2.     private JFreeChart chart;
  3.     public String execute() throws Exception {
  4.         // chart creation logic...
  5.         XYSeries dataSeries = new XYSeries(new Integer(1)); //pass a key for this serie
  6.         for (int i = 0; i <= 100; i++) {
  7.             dataSeries.add(i, RandomUtils.nextInt());
  8.         }
  9.         XYSeriesCollection xyDataset = new XYSeriesCollection(dataSeries);
  10.         ValueAxis xAxis = new NumberAxis("Raw Marks");
  11.         ValueAxis yAxis = new NumberAxis("Moderated Marks");
  12.         // set my chart variable
  13.         chart =
  14.             new JFreeChart(
  15.                 "Moderation Function",
  16.                 JFreeChart.DEFAULT_TITLE_FONT,
  17.                 new XYPlot(
  18.                     xyDataset,
  19.                     xAxis,
  20.                     yAxis,
  21.                     new StandardXYItemRenderer(StandardXYItemRenderer.LINES)),
  22.                 false);
  23.         chart.setBackgroundPaint(java.awt.Color.white);
  24.         return super.SUCCESS;
  25.     }
  26.     public JFreeChart getChart() {
  27.         return chart;
  28.     }
  29. }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值