我正在运行一个程序来使用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的新手。
答案 0 :(得分:2)
添加代码的步骤: