java.lang.ClassCastException: org.jfree.chart.JFreeChart cannot be cast to java.lang.String
请大家帮我看一下,很急的,谢谢各位了。
代码如下:
package com.sinews.insurance.action;
import java.awt.Color;
import java.awt.Font;
import java.io.IOException;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.labels.StandardCategoryItemLabelGenerator;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer3D;
import org.jfree.chart.renderer.category.CategoryItemRenderer;
import org.jfree.chart.renderer.category.LineAndShapeRenderer;
import org.jfree.chart.title.LegendTitle;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.general.DatasetUtilities;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.ui.RectangleInsets;
import com.opensymphony.xwork2.ActionSupport;
public class JFreeChartCateGoryAction extends ActionSupport{
private JFreeChart chart;
public JFreeChart getChart() {
return chart;
}
public void setChart(JFreeChart chart) {
this.chart = chart;
}
/*******************************************折线图**************************************************/
public JFreeChart getXYChartAction(){
System.out.println("折线图getXYChartAction");
double[][] data=new double[][]
{
{676,766,223,540,126},
{222,540,456,678,345},
{512,412,621,426,532}
};
String[] rowKyes={"苹果","香蕉","李子"};
String[] columnKyes={"北京","上海","广州","城都","深圳"};
CategoryDataset dataset=getBarData(data,rowKyes,columnKyes);
createTimeXYChar("折线图","x轴","y轴",dataset,"");
return chart;
}
public CategoryDataset getBarData(double[][] data,String[] rowKyes,String[] columnKeys){
return DatasetUtilities.createCategoryDataset(rowKyes, columnKeys,data);
}
public void createTimeXYChar(String chartTitle,String x,String y,CategoryDataset xyDataset,String chartName){
chart=ChartFactory.createLineChart(chartTitle, x, y, xyDataset, PlotOrientation.VERTICAL, true, true, false);
Font font00=new Font("宋体",Font.BOLD,18);
LegendTitle legend=chart.getLegend();
legend.setItemFont(font00);//设置注释字体
chart.setTextAntiAlias(false);
//设置图标题的字体重新设置title
Font font=new Font("隶书",Font.BOLD,25);
TextTitle title=new TextTitle(chartTitle);
title.setFont(font);
chart.setTitle(title);
CategoryPlot categoryplot=(CategoryPlot)chart.getPlot();
//x轴分类轴网格是否可见
categoryplot.setDomainGridlinesVisible(true);
//y轴数据轴网格是否可见
categoryplot.setRangeGridlinesVisible(true);
categoryplot.setRangeGridlinePaint(Color.pink);//虚线色彩
categoryplot.setDomainGridlinePaint(Color.pink);//虚线色彩
categoryplot.setBackgroundPaint(Color.white);
//设置轴和板之间的距离
categoryplot.setAxisOffset(new RectangleInsets(0D,0D,0D,0D));
CategoryAxis domainAxis=categoryplot.getDomainAxis();
domainAxis.setLabelFont(new Font("宋体",Font.BOLD,18));//轴标题
domainAxis.setTickLabelFont(new Font("宋体",Font.ITALIC,15));//轴数值
domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);//横轴上的
//设置距离图片左端距离
domainAxis.setLowerMargin(0.1);
//设置距离图片右端距离
domainAxis.setUpperMargin(0.1);
NumberAxis numberaxis=(NumberAxis)categoryplot.getRangeAxis();
numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
numberaxis.setAutoRangeIncludesZero(true);
numberaxis.setLabelFont(new Font("宋体",Font.BOLD,18));
//设置最高的一个值与图片顶端的距离
numberaxis.setUpperMargin(0.15);
//设置最低的一个值与图片低端的距离
// numberaxis.setLowerMargin(0.15);
//获得renderer
LineAndShapeRenderer lineandshaperrenderer=(LineAndShapeRenderer)categoryplot.getRenderer();
lineandshaperrenderer.setBaseShapesVisible(true);//series点(即数据点)可见
lineandshaperrenderer.setBaseLinesVisible(true);//series点(即数据点)间有连线可见
//现设折点数据
lineandshaperrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
lineandshaperrenderer.setBaseItemLabelsVisible(true);
}
/*******************************************折线图结束**************************************************/
}
struts2配置如下:
600
450
一直抱上面的那个错,不知道怎么回事。