`

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.

 

分享到:
评论
2 楼 redsnow_fenglin 2009-11-04  
fejay 写道
英文的,看不懂啊

不好意思,因为原本要把他发到apache网站,所以,写了英文;
本文的大致意思是:
希望大家分享自己改良的开源代码,因为第三方插件并不是完美无瑕的;
本文说的是官方struts2-jfreechart-plugin-2.1.8.jar存在不足:1、仅仅只是展示jfreechart报表,不能呈现鼠标提示及超链接,即丢失jfreechart中我们设置的urltips及tooltips;2、jfreechart默认的是png格式,当我们配成jpg或jpeg格式时,web页面就无法展示图片而变成你的action下载提示了;
本文给出的源码及jar就是解决上面两个问题的,其中的example是展示如何使用我给出的struts2-jfreechart-plugin-2.1.8.1.jar的使用方法,当然,我们还可以从中学习到jfreechart折线图的一种产生方法及是否展示节点、节点数据、如何设置tooltips和urltips等jfreechart的知识;我们需要注意的是<param name="mode">enchanced</param>这个配置,参数mode若配为stand即采用官方标准模式(当然是解决了bug 2),若配为enchanced即采用我们给出的加强模式(解决了bug 1和2),这个也是默认模式;

同时也提及了在我的blog中所指出的关于struts2-jasperreport-plugin-2.1.6.jar的不足及改良,详细信息可以参考  http://redsnow-fenglin.iteye.com/blog/464213 and http://redsnow-fenglin.iteye.com/blog/461927,关于源码及jar可以访问 http://redsnow-fenglin.iteye.com/blog/508715
1 楼 fejay 2009-11-02  
英文的,看不懂啊

相关推荐

    struts2-jfreechart-plugin-2.1.8.1.jar

    struts2-jfreechart-plugin-2.1.8.1.jar

    struts2-jfreechart-plugin-2.1.8.1

    struts2-jfreechart-plugin-2.1.8.1

    struts2-jfreechart-plugin-2.0.11.jar

    struts2-jfreechart-plugin-2.0.11.jarstruts2-jfreechart-plugin-2.0.11.jarstruts2-jfreechart-plugin-2.0.11.jar

    struts2-jfreechart-plugin-2.3.4.1.jar

    struts2-jfreechart-plugin-2.3.4.1.jar

    struts2-jfreechart-plugin-2.0.8.jar

    struts2-jfreechart-plugin-2.0.8.jar

    struts2-jfreechart-plugin-2.1.6.jar

    struts2-jfreechart-plugin-2.1.6.jar

    struts2-jfreechart-plugin-2.2.3.jar

    struts2 结合强大的图形报表开发包进行集成开发,能够降低系统的耦合和灵活的报表开发方式,展现不同的图形化报表,给企业带来更加精美的报表解决方案。

    Struts2开发常用jar包

    包含struts2-core-2.5.10.1.jar,struts2-jfreechart-plugin-2.5.10.1.jar,struts2-json-plugin-2.5.10.1.jar,struts2-junit-plugin-2.5.10.1.jar,struts2-bean-validation-plugin-2.5.10.1.jar,struts2-cdi-...

    Struts2-3.24集合jar

    struts2-jfreechart-plugin-2.3.24.jar, struts2-pell-multipart-plugin-2.3.24.jar, struts2-plexus-plugin-2.3.24.jar, struts2-sitegraph-plugin-2.3.24.jar, struts2-sitemesh-plugin-2.3.24.jar, struts2-...

    struts2-jfreechart-plugin-2.1.8

    最新官方struts2-plugin jfreechart,分享于有需要的朋友

    如何修改struts2-jfreechart-plugin2.0.11jar包

    ### 如何修改struts2-jfreechart-plugin 2.0.11 jar包 #### 一、概述 本文档将详细介绍如何对`struts2-jfreechart-plugin 2.0.11`版本的jar包进行修改。Struts2是一个基于Java的Web应用框架,而JFreeChart则是一款...

    struts2-jfreechart-plugin-2.3.15.3.jar

    struts2整合jfreechart 的工具jar文件 struts2-jfreechart-plugin-2.3.15.3.jar

    struts2-jfreechart-plugin-2.1.6.jar.zip_jfreechart struts2_jfree

    "struts2-jfreechart-plugin-2.1.6.jar.zip_jfreechart struts2_jfree" 这个标题表明这是一个关于Struts2与JFreeChart结合使用的插件,版本为2.1.6。这个插件简化了在Struts2应用中使用JFreeChart的过程,使得开发者...

    struts-2.5.2-all所有jar包

    struts2-jfreechart-plugin-2.5.2.jar, struts2-json-plugin-2.5.2.jar, struts2-junit-plugin-2.5.2.jar, struts2-osgi-admin-bundle-2.5.2.jar, struts2-osgi-demo-bundle-2.5.2.jar, struts2-osgi-plugin-2.5.2....

    javaweb开发包大全

    比较全的java开发包,要用到的朋友可以下载 ...struts2-convention-plugin-2.1.8.1.jar struts2-core-2.1.8.1.jar struts2-embeddedjsp-plugin-2.1.8.1.jar struts2-json-plugin-2.1.8.1.jar xwork-core-2.1.6.jar

    struts-2.5.10-all所有jar包

    struts2-gxp-plugin-2.5.10.jar,struts2-jasperreports-plugin-2.5.10.jar,struts2-javatemplates-plugin-2.5.10.jar,struts2-jfreechart-plugin-2.5.10.jar,struts2-json-plugin-2.5.10.jar,struts2-junit-plugin-...

    struts2-junit-plugin-2.1.6.jar

    struts2-junit-plugin-2.1.6.jar

    struts-2.3.30-all所有jar包

    struts2-jfreechart-plugin-2.3.30.jar, struts2-jsf-plugin-2.3.30.jar, struts2-json-plugin-2.3.30.jar, struts2-junit-plugin-2.3.30.jar, struts2-osgi-admin-bundle-2.3.30.jar, struts2-osgi-demo-bundle-...

    struts2-tags-文档.rar

    Struts2是一个强大的Java web应用程序框架,它基于MVC(模型-视图-控制器)设计模式,用于构建可维护性和可扩展性高的企业级应用。Struts2的标签库是其核心特性之一,极大地简化了视图层的开发,提高了开发效率。本...

    Struts2 -JFreeChart

    Struts2 -JFreeChartStruts2 -JFreeChartStruts2 -JFreeChartStruts2 -JFreeChartStruts2 -JFreeChartStruts2 -JFreeChartStruts2 -JFreeChartStruts2 -JFreeChartStruts2 -JFreeChart

Global site tag (gtag.js) - Google Analytics