vinegardou 2011-02-11 18:00 采纳率: 0%
浏览 228
已采纳

这个是什么异常?

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



一直抱上面的那个错,不知道怎么回事。

  • 写回答

4条回答 默认 最新

  • iteye_17587 2011-02-12 10:40
    关注

    但是从你贴出的异常信息看,也不是来自类JFreeChartCateGoryAction的呀

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥100 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名