Created
October 11, 2010 00:15
-
-
Save kimukou/619747 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// g100pon #90 JFreeChartでグラフ生成 | |
// | |
//from waman sample copy | |
// | |
@Grab(group='jfree', module='jfreechart', version='1.0.12') | |
import org.jfree.chart.* | |
import org.jfree.chart.plot.* | |
import org.jfree.data.category.* | |
import org.jfree.data.general.DefaultPieDataset | |
ChartFactory.chartTheme = StandardChartTheme.createLegacyTheme() // 文字化け対策 | |
dcd = new DefaultCategoryDataset() | |
dcd.with { | |
addValue(80, "A店", "Jan 2010") | |
addValue(110, "A店", "Feb 2010") | |
addValue(120, "A店", "Mar 2010") | |
addValue(50, "B店", "Jan 2010") | |
addValue(120, "B店", "Feb 2010") | |
addValue(80, "B店", "Mar 2010") | |
} | |
def jfc = ChartFactory.createStackedBarChart( | |
"売上推移", | |
"年月", | |
"売上", | |
dcd, | |
PlotOrientation.VERTICAL, | |
true, | |
false, | |
false) | |
def dataset = new DefaultPieDataset(); | |
dataset.with{ | |
setValue('4月', 10) | |
setValue('5月', 30) | |
setValue('6月', 40) | |
} | |
def chart = ChartFactory.createPieChart('円グラフのサンプル', dataset, true, true, true) | |
chart.backgroundPaint = Color.WHITE | |
//---------------------------------------------------------------------------- | |
import groovy.swing.SwingBuilder | |
import java.awt.* | |
import javax.swing.WindowConstants as WC | |
def swingBuilder = new SwingBuilder() | |
swingBuilder.edt { | |
frame(title:'graph_test', | |
//size: [300,300], | |
pack: true, | |
location: [50,50], | |
resizable: true, | |
locationByPlatform:true, | |
show: true, | |
defaultCloseOperation:WC.EXIT_ON_CLOSE | |
) | |
{ | |
tabbedPane(){ | |
panel(title:"bar-chart"){ | |
widget(new ChartPanel(jfc)) | |
} | |
panel(title:'canvas') { | |
widget(new ChartPanel(chart)) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment