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-積上棒グラフ-DefaultCategoryDataset

Posted at

目次 ⇒ JFreeChartサンプル

package jp.avaj.lib.chart;

import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.Plot;
import org.jfree.chart.renderer.category.CategoryItemRenderer;
import org.jfree.chart.renderer.category.StackedBarRenderer;
import org.jfree.data.category.DefaultCategoryDataset;

/**
■ JFreeChart-積上棒グラフ-DefaultCategoryDataset
・複数の商品売上の合計を表示するようなものに使用される.
・StackedBarRendererを使用すると同一ColumnKeyのデータが積み上げられる.

 */
public class Chart08_00 {
  // 目次-積上げバーチャート(StackedBarChart)
  A_Chart08 a_Chart08;
  // 目次-Artery-JFreeChart用のライブラリ
  A_Chart00 a_LibChartSampeContents;

  public static void main(String[] args) {
    // 表示データの作成
    DefaultCategoryDataset dataSet = new DefaultCategoryDataset();
    {
      //
      dataSet.addValue(136.5,"商品A","2014");
      dataSet.addValue(206.1,"商品A","2015");
      dataSet.addValue(296.7,"商品A","2016");
      //
      dataSet.addValue( 40.5,"商品B","2014");
      dataSet.addValue(105.7,"商品B","2015");
      dataSet.addValue(199.4,"商品B","2016");
      //
      dataSet.addValue(150.5,"商品C","2014");
      dataSet.addValue(87.5,"商品C","2015");
      dataSet.addValue(40.0,"商品C","2016");
    }
    //
    CategoryAxis catAxis = new CategoryAxis();
    NumberAxis numAxis = new NumberAxis();
    // 積上棒グラフにはStackedBarRendererを使用する
    StackedBarRenderer renderer = new StackedBarRenderer();
    CategoryPlot catPlot = new CategoryPlot(dataSet,catAxis,numAxis,(CategoryItemRenderer)renderer); // (1)
    JFreeChart jfreeChart = new JFreeChart("売上構成の変化",(Plot)catPlot);
    //
    ChartFrame cFrame = new ChartFrame("売上構成の変化",(JFreeChart)jfreeChart);
    cFrame.pack();
    cFrame.setVisible(true);
  }
}

無題.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?