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.