opensource for struts2-jfreechart-plugin-2.1.8.1

I wish we all could share our knowledge each other,especially the open project

 

*Brief introduction::extend the function of jfreechart-plugin to display the tips' info you've set in the web browser.
 *    And fix the bug of jpg undisplayed.(just use response.setContentType("image/jpeg") instead of response.setContentType("image/jpg"))
 *

 

About struts2,we know it use the mechanism of plugin to hook others' third part. However we'll find some blemish or bugs with going deep into using them,for example,one is struts2-jasperreport-plugin-2.1.6 introduced by us in my blog's article http://redsnow-fenglin.iteye.com/blog/464213 and http://redsnow-fenglin.iteye.com/blog/461927, and the other one is the one which we're discussing now the struts2-jfreechart-plugin-2.1.8.1,whoe bug is that could not display the tips' info you've set in the web browser and the jpg's format.

 

Here, I just introduce the later instance. I extend the class ChartResult to extend the function of jfreechart-plugin to display the tips' info you've set in the web browser.And fix the bug of jpg undisplayed.(just use response.setContentType("image/jpeg") instead of response.setContentType("image/jpg")). There is an used example in the source coe of EnhancedChartResult.java, smple codes as following:

 

 <!-- START SNIPPET: example -->

public class ExampleChartAction extends ActionSupport {

private JFreeChart chart;

public String execute() throws Exception {
        String title = "Report Title Here";
        String xAxisLabel = "X Axis Mark";
        String yAxisLabel = "Y Axis Mark";

        double[][] yKeysVale = new double[][] {{621,890,591,591,528,621}};
        String[] yKeys = {"Error Files"};
        String[] xKeys = {"2009-01","2009-02","2009-03","2009-04","2009-05","2009-06"};
        CategoryDataset dataset = DatasetUtilities.createCategoryDataset(yKeys,xKeys,yKeysVale);
        chart = ChartFactory.createLineChart(title, xAxisLabel, yAxisLabel, dataset, PlotOrientation.VERTICAL, true, true, false);
        chart.setBackgroundPaint(Color.WHITE);
        CategoryPlot categoryplot = (CategoryPlot) chart.getPlot();
        // x轴 // 分类轴网格是否可见
        categoryplot.setDomainGridlinesVisible(true);
        // y轴 //数据轴网格是否可见
        categoryplot.setRangeGridlinesVisible(true);
        categoryplot.setRangeGridlinePaint(Color.WHITE);// 虚线色彩
        categoryplot.setDomainGridlinePaint(Color.WHITE);// 虚线色彩
        categoryplot.setBackgroundPaint(Color.lightGray);
        // 设置轴和面板之间的距离
        categoryplot.setAxisOffset(new RectangleInsets(0D, 0D, 0D, 0D));
        // 获得renderer 注意这里是下转型到lineandshaperenderer!!
        LineAndShapeRenderer lineandshaperenderer = (LineAndShapeRenderer) categoryplot.getRenderer();
        lineandshaperenderer.setBaseShapesVisible(true); // series 点(即数据点)可见
        lineandshaperenderer.setBaseLinesVisible(true); // series 点(即数据点)间有连线可见
  lineandshaperenderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator("link.jsp","series","hits")); // 设置超链接
        // 显示折点数据
         lineandshaperenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
         lineandshaperenderer.setBaseItemLabelsVisible(true);
         

  // 横轴上的 Lable 45度倾斜
        domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); 
        NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
        numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        numberaxis.setAutoRangeIncludesZero(false);     

            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="mode">enchanced</param>
   <param name="value">chart</param>
   <param name="type">png</param>
   <param name="width">640</param>
   <param name="height">480</param>
</result>

 
  Tips: enchanced is the default value of the param mode , and another value you can use is stand,which stands for the original value of struts-plugin-2.1.8.jar.
<!-- END SNIPPET: example -->

 

If you want to know the more details , you could download the source code from the appurtenance.

 

Tips:My apache topic is http://www.quicktopic.com/43/H/23NsPYee3Y4Eg.

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值