gpt4 book ai didi

grails - Grails JFreeChart无法解析类:org.jfree.chart.ChartFactory

转载 作者:行者123 更新时间:2023-12-02 15:06:13 27 4
gpt4 key购买 nike

我正在运行一个程序,使用JFreeChart库和Groovy / Grails后端绘制折线图。这是我的代码:

    package com.xyz.jfreechartdemo

import org.jfree.chart.ChartFactory
import org.jfree.chart.JFreeChart
import org.jfree.chart.plot.PlotOrientation
import org.jfree.data.category.DefaultCategoryDataset

class JFreeChartSample {
def getChart(){
def dataset = createDataset()
def chart = createChart(dataset)
return chart
}

def createDataset() {
DefaultCategoryDataset dataset = new DefaultCategoryDataset()
dataset.addValue(2000,"X",1)
dataset.addValue(3300,"X",2)
dataset.addValue(2000,"X",3)
dataset.addValue(3300,"X",4)
return dataset
}

def createChart(dataset){
JFreeChart chart = ChartFactory.createLineChart("Widget not rendered","X","Count",dataset,PlotOrientation.VERTICAL,false,true,false)
return chart
}
}

我正在研究IntelliJ Idea 13.1.3。编译成功。但是,这是我运行程序时看到的内容:
Compilation error: startup failed:
C:\Users\User\IdeaProjects\JFreeChartDemo\grails app\domain\com\xyz\jfreechartdemo\JFreeChartSample.groovy: 3: unable to resolve class org.jfree.chart.ChartFactory
@ line 3, column 1.
import org.jfree.chart.ChartFactory
^

C:\Users\User\IdeaProjects\JFreeChartDemo\grails-app\domain\com\xyz\jfreechartdemo\JFreeChartSample.groovy: 6: unable to resolve class org.jfree.data.category.DefaultCategoryDataset
@ line 6, column 1.
import org.jfree.data.category.DefaultCategoryDataset
^

C:\Users\User\IdeaProjects\JFreeChartDemo\grails-app\domain\com\xyz\jfreechartdemo\JFreeChartSample.groovy: 5: unable to resolve class org.jfree.chart.plot.PlotOrientation
@ line 5, column 1.
import org.jfree.chart.plot.PlotOrientation
^

C:\Users\User\IdeaProjects\JFreeChartDemo\grails-app\domain\com\xyz\jfreechartdemo\JFreeChartSample.groovy: 4: unable to resolve class org.jfree.chart.JFreeChart
@ line 4, column 1.
import org.jfree.chart.JFreeChart
^

4 errors

我已经将JCommon和所有JFreeChart库复制到lib文件夹中。而且我仍然看到此错误。请帮忙。我对Groovy和Grails非常陌生。

最佳答案

添加代码的步骤:

  • 添加您的jar依赖关系,它将在BuildConfig.groovy中下载它(您需要通过在Web上在线搜索jar版本来找到如何使用maven存储库下载它)
    http://mvnrepository.com/artifact/jfree/jfreechart
  • 运行“grails clean”
  • 运行“grails刷新依赖项”
  • 关于grails - Grails JFreeChart无法解析类:org.jfree.chart.ChartFactory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28871218/

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