gpt4 book ai didi

java - 类型转换错误

转载 作者:行者123 更新时间:2023-12-01 17:35:29 25 4
gpt4 key购买 nike

public class xyArea{
public static void main(String arg[]){
XYSeries series = new XYSeries("Average Weight");
series.add(20.0, 20.0);
series.add(40.0, 25.0);
series.add(55.0, 50.0);
series.add(70.0, 65.0);
XYDataset xyDataset = new XYSeriesCollection(series);
JFreeChart chart = ChartFactory.createAreaChart
("XY Chart using JFreeChart", "Age", "Weight",
(CategoryDataset) xyDataset, PlotOrientation.VERTICAL, true,
true, false);
ChartFrame frame1=new ChartFrame("XYArea Chart",chart);
frame1.setVisible(true);
frame1.setSize(300,300);
}
}

我编写了这段代码,但出现了以下错误,请指导我:

线程“main”中的异常 java.lang.ClassCastException:org.jfree.data.xy.XYSeriesCollection 无法转换为 org.jfree.data.CategoryDataset 在 xyArea.main(xyArea.java:21)

最佳答案

嗯,您无法转换为 CategoryDataset,因为 XYSeriesCollection 不是 CategoryDataset

看来您需要.createXYAreaChart(..)(而不是.createAreaChart(..))

关于java - 类型转换错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6812926/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com