0
0

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-複数パイチャート(MultiplePieChart)

Posted at

目次 ⇒ JFreeChartサンプル

package jp.avaj.lib.chart;

import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.MultiplePiePlot;
import org.jfree.chart.plot.Plot;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;

/**
JFreeChart-複数パイチャート(MultiplePieChart)

・MultiplePiePlotを使用すると複数のパイチャートを表示することができる.
・PiePlotを組み合われるのではなく、独自のPlotが用意されている.

・DatasetはDefaultCategoryDatasetを使用する.

・サンプルに示したのは、複数のスーパーの売上の比較.
・同様の事例としては各国のGDP構成の比較、家庭の出費の比較などなど.

・残念ながらパイチャートの時のように、特定のデータを強調したり、色を変えたりはできない.

 */
public class Chart05_00 {
  // 目次-複数パイチャート(MultiplePieChart)
  A_Chart05 a_Chart05;
  // 目次-Artery-JFreeChart用のライブラリ
  A_Chart00 a_LibChartSampeContents;


  public static void main(String[] args) {
    //
    // Datasetの作成-ColumnKeyごとにパイチャートが作成される
    DefaultCategoryDataset dataSet = createSalesData();
    // Plotの作成
    MultiplePiePlot multiplePiePlot = new MultiplePiePlot((CategoryDataset)dataSet);
    JFreeChart jfreeChart = new JFreeChart("スーパー売上構成",(Plot)multiplePiePlot);
    //
    ChartFrame cFrame = new ChartFrame("スーパー売上構成",(JFreeChart)jfreeChart);
    cFrame.pack();
    cFrame.setVisible(true);
  }
  private static DefaultCategoryDataset createSalesData() {
    // ColumnKeyごとにパイチャートが作成される
    DefaultCategoryDataset dataSet = new DefaultCategoryDataset();
    // A店
    dataSet.addValue(100,"生鮮食品","A");
    dataSet.addValue(80,"加工食品","A");
    dataSet.addValue(40,"日用品","A");
    dataSet.addValue(30,"電器","A");
    dataSet.addValue(30,"服飾","A");
    dataSet.addValue(40,"雑貨","A");
    // B店
    dataSet.addValue(50,"生鮮食品","B");
    dataSet.addValue(20,"加工食品","B");
    dataSet.addValue(30,"日用品","B");
    dataSet.addValue(30,"電器","B");
    dataSet.addValue(70,"服飾","B");
    dataSet.addValue(50,"雑貨","B");
    // C店
    dataSet.addValue(70,"生鮮食品","C");
    dataSet.addValue(40,"加工食品","C");
    dataSet.addValue(30,"日用品","C");
    //
    return dataSet;
  }
}

無題.png

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?