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; i < itmes.length; i++ ) {

    nSum += itmes[i][0];

  }

  

  for (int i = 0; i < itmes.length; i++) {

    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);  // uncoment to reproduce a bug in jFreeChart

  //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);


저작자 표시
신고
posted by 뚱2


  import org.jfree.chart.ChartFactory

  import org.jfree.chart.ChartFrame

  import org.jfree.chart.ChartUtilities

  import org.jfree.chart.JFreeChart

  import org.jfree.chart.plot.PlotOrientation

  import org.jfree.chart.plot.CategoryPlot

  import org.jfree.chart.ChartRenderingInfo

  import org.jfree.chart.entity.StandardEntityCollection

  import org.jfree.data.xy.*

  import org.jfree.data.category.DefaultCategoryDataset

  // 데이타셋

  DefaultCategoryDataset dataset = new DefaultCategoryDataset();

  

  int[] nCatSum = new int[]{0, 0, 0, 0};

  

  for (int i=0; i < 12; i++) {

    for (int j=0; j < nCatSum.length; j++) {

      dataset.addValue(nCatSum[j], "카테고리"+(j+1), ""+(i+1)+"월");

      nCatSum[j] += i+j;

    }

  }


  // 차트

  JFreeChart chart = ChartFactory.createStackedBarChart(

      "Bar Chart"

      , "X축"

      , "Y축"

      , dataset

      , PlotOrientation.VERTICAL

      , true

      , true

      , false);

  

  chart.setBackgroundPaint(java.awt.Color.white);

  chart.setTitle("제목");

  

  ////////////////////////////////////////////////////////////////

  // 한글 깨짐 해결

  

  // 제목

  chart.getTitle().setFont(new Font("돋움", Font.BOLD, 15));

  // 범례

  chart.getLegend().setItemFont(new Font("돋움", Font.PLAIN, 10));

  

  CategoryPlot plot = chart.getCategoryPlot();

  

  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));


  

  // 파일 저장

  ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());

  String fileName= "C:/" + "stactedChart.jpg";

  ChartUtilities.saveChartAsJPEG(new File(fileName),chart,800,450,info);


저작자 표시
신고
posted by 뚱2