81,092
社区成员
发帖
与我相关
我的任务
分享
页面:
<img alt="" src="<%=request.getContextPath()%>/https/mystruts/test_view_picture.html" />
urlRewrite:
<rule>
<from>^/https/mystruts/test_view_picture.html$</from>
<to>/pages/mystruts/testViewPicture.action</to>
</rule>
struts-config:
<package name="pic" extends="jfreechart-default" namespace="/pages/mystruts">
<action name="testViewPicture" class="com.ito.hsr.action.get.TestViewPictureAction" method="getChart">
<result name="success" type="chart">
<param name="width">600</param>
<param name="height">450</param>
</result>
</action>
</package>
public class TestViewPictureAction extends ActionSupport{
public JFreeChart getChart(){
JFreeChart chart = ChartFactory.createPieChart3D(
"图书统计图", // 图表标题
getDataSet(), //数据
true, // 是否显示图例
false, //是否显示工具提示
false //是否生成URL
);
//重新设置图标标题,改变字体
chart.setTitle(new TextTitle("图书统计图", new Font("黑体", Font.ITALIC , 22)));
//取得统计图标的第一个图例
LegendTitle legend = chart.getLegend(0);
//修改图例的字体
legend.setItemFont(new Font("宋体", Font.BOLD, 14));
//获得饼图的Plot对象
PiePlot plot = (PiePlot)chart.getPlot();
//设置饼图各部分的标签字体
plot.setLabelFont(new Font("隶书", Font.BOLD, 18));
//设定背景透明度(0-1.0之间)
plot.setBackgroundAlpha(0.9f);
//设定前景透明度(0-1.0之间)
plot.setForegroundAlpha(0.50f);
System.out.println("chart===="+chart);
return chart;
}
private DefaultPieDataset getDataSet(){
DefaultPieDataset dataset = new DefaultPieDataset();
dataset.setValue("Spring2.0",47000);
dataset.setValue("J2EE",38000);
dataset.setValue("Ajax",31000);
dataset.setValue("JavaScript",29000);
dataset.setValue("Ajax In Action",25000);
return dataset;
}
}
<package name="jFreeChartDemonstration" extends="struts-default" namespace="/jfreechart"> <result-types>
<result-type name="chart" class="org.apache.struts2.dispatcher.ChartResult"></result-type> </result-types>
<action name="JFreeChartAction" class="com.tangjun.struts2.JFreeChartAction">
<result type="chart">
<param name="width">400</param>
<param name="height">300</param>
</result>
</action>
</package>
<action name="testViewPicture" class="com.ito.hsr.action.get.TestViewPictureAction" method="getChart">
<result name="success" type="chart">
<param name="width">600</param>
<param name="height">450</param>
</result>
</action>
java.lang.ClassCastException: org.jfree.chart.JFreeChart