我正在运行一个程序,使用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:UsersUserIdeaProjectsJFreeChartDemograils appdomaincomxyzjfreechartdemoJFreeChartSample.groovy: 3: unable to resolve class org.jfree.chart.ChartFactory
@ line 3, column 1.
import org.jfree.chart.ChartFactory
^
C:UsersUserIdeaProjectsJFreeChartDemograils-appdomaincomxyzjfreechartdemoJFreeChartSample.groovy: 6: unable to resolve class org.jfree.data.category.DefaultCategoryDataset
@ line 6, column 1.
import org.jfree.data.category.DefaultCategoryDataset
^
C:UsersUserIdeaProjectsJFreeChartDemograils-appdomaincomxyzjfreechartdemoJFreeChartSample.groovy: 5: unable to resolve class org.jfree.chart.plot.PlotOrientation
@ line 5, column 1.
import org.jfree.chart.plot.PlotOrientation
^
C:UsersUserIdeaProjectsJFreeChartDemograils-appdomaincomxyzjfreechartdemoJFreeChartSample.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中下载它(您需要通过在网上搜索您的jar版本来找到如何使用maven存储库下载它)http://mvnrepository.com/artifact/jfree/jfreechart
- 运行"grails clean"
- 运行"grails刷新依赖项"