
import java.io.*
import java.awt.Font
import java.awt.Color
improt java.awt.GradientPaint
import org.jfree.chart.ChartFactory
import org.jfree.chart.ChartPanel
import org.jfree.chart.JFreeChart
import org.jfree.chart.axis.NumberAxis
import org.jfree.chart.plot.PlotOrientation
import org.jfree.chart.plot.XYPlot
import org.jfree.chart.ChartRenderingInfo
import org.jfree.chart.ChartUtilities
import org.jfree.chart.plot.CategoryPlot
import org.jfree.data.xy.MatrixSeriesCollection>
import org.jfree.data.xy.NormalizedMatrixSeries
import org.jfree.ui.ApplicationFrame
import org.jfree.ui.RefineryUtilities
final int SIZE = 20
final MatrixSeriesCollection dataset = new MatrixSeriesCollection()
// value, x, y
int[][] itmes = {
{200, 3 , 12}
,{250, 8 , 5 }
,{80 , 14, 16}
,{50 , 18, 4 }
}
int nSum = 0
for (int i = 0
nSum += itmes[i][0]
}
for (int i = 0
NormalizedMatrixSeries newSeries =
new NormalizedMatrixSeries("대카테고리" + (i+1), SIZE, SIZE)
newSeries.update(itmes[i][2], itmes[i][1], itmes[i][0])
newSeries.setScaleFactor(SIZE*((float)itmes[i][0]/nSum))
dataset.addSeries(newSeries)
}
final JFreeChart chart = ChartFactory.createBubbleChart(
"Bubble Chart"
, "X축"
, "Y축"
, dataset
, PlotOrientation.VERTICAL
, true
, true
, false)
chart.setBackgroundPaint(Color.white)
chart.setTitle("제목")
// 제목
chart.getTitle().setFont(new Font("돋움", Font.BOLD, 15))
// 범례
chart.getLegend().setItemFont(new Font("돋움", Font.PLAIN, 12))
final XYPlot plot = chart.getXYPlot()
Font font = plot.getDomainAxis().getLabelFont()
// X축 라벨
plot.getDomainAxis().setLabelFont(new Font("돋움", font.getStyle(), font.getSize()))
// X축 도메인
plot.getDomainAxis().setTickLabelFont(new Font("돋움", font.getStyle(), 10))
font = plot.getRangeAxis().getLabelFont()
// Y축 라벨
plot.getRangeAxis().setLabelFont(new Font("돋움", font.getStyle(), font.getSize()))
// Y축 범위
plot.getRangeAxis().setTickLabelFont(new Font("돋움", font.getStyle(), 10))
//final XYPlot plot = chart.getXYPlot()
plot.setForegroundAlpha(0.5f)
final NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis()
//domainAxis.setLowerBound(-0.5)
domainAxis.setLowerBound(0)
final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis()
// rangeAxis.setInverted(true)
//rangeAxis.setLowerBound(-0.5)
rangeAxis.setLowerBound(0)
// 파일 저장
ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection())
String fileName= "C:/" + "bubbleChart.jpg"
ChartUtilities.saveChartAsJPEG(new File(fileName),chart,600,400,info)
RECENT COMMENT