1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

JFreeChart-パイチャート

Last updated at Posted at 2019-06-30

目次 ⇒ JFreeChartサンプル

package jp.avaj.lib.chart;

import java.awt.Color;
import java.lang.reflect.InvocationTargetException;

import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PiePlot;
import org.jfree.chart.plot.Plot;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.general.PieDataset;

/** JFreeChart-パイチャート */
public class Chart04_00 {
  // 目次-パイチャート(PieChart)
  A_Chart04 a_Chart04;
  // 目次-Artery-JFreeChart用のライブラリ
  A_Chart00 a_LibChartSampeContents;


  /** 商品の売上数のデータからパイチャートを生成する */
  public static void main(String[] args) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
    // PieDatasetを作成する
    DefaultPieDataset dataSet = new DefaultPieDataset();
    dataSet.setValue("商品A",200);
    dataSet.setValue("商品B",150);
    dataSet.setValue("商品C",90);
    dataSet.setValue("商品D",120);
    dataSet.setValue("商品E",230);

    // Plotを生成する
    PiePlot piePlot = new PiePlot((PieDataset)dataSet);
    // 3Dパイチャートならば次のようにする
    //piePlot = (PiePlot)new PiePlot3D((PieDataset)dataSet);

    // 商品cを強調して表示する,値は結果を見て調整する
    piePlot.setExplodePercent("商品C",0.1D);

    // 商品bの色を変える,注、指定しなければJFreeChartが勝手に決める
    piePlot.setSectionPaint("商品B", Color.black);

    // チャートを生成する
    JFreeChart jfreeChart = new JFreeChart("商品別売上高",(Plot)piePlot);
    //
    ChartFrame cFrame = new ChartFrame("PieChartFrame",(JFreeChart)jfreeChart);
    cFrame.pack();
    cFrame.setVisible(true);
  }
}

無題.png

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?