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-バーチャート(BarChart)

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.BarRenderer;
import org.jfree.chart.renderer.category.CategoryItemRenderer;
import org.jfree.data.category.DefaultCategoryDataset;

/** JFreeChart-バーチャート(BarChart) */
public class Chart07_00 {
  // 目次-バーチャート(BarChart)
  A_Chart07 a_Chart07;
  // 目次-Artery-JFreeChart用のライブラリ
  A_Chart00 a_LibChartSampeContents;

  public static void main(String[] args) {
    //
    // 表示データを作成する,DefaultCategoryDatasetを使用する
    DefaultCategoryDataset catDataSet = new DefaultCategoryDataset();
    {
      catDataSet.addValue(54,"2009","民進");
      catDataSet.addValue(38,"2009","自民");
      catDataSet.addValue(23,"2009","公明");
      catDataSet.addValue( 8,"2009","共産");
      catDataSet.addValue( 4,"2009","無所属");
      catDataSet.addValue( 2,"2009","ネット");
      //
      catDataSet.addValue(59,"2013","自民");
      catDataSet.addValue(23,"2013","公明");
      catDataSet.addValue(17,"2013","共産");
      catDataSet.addValue(15,"2013","民進");
      catDataSet.addValue( 7,"2013","みんな");
      catDataSet.addValue( 3,"2013","ネット");
      catDataSet.addValue( 2,"2013","維新");
      catDataSet.addValue( 1,"2013","無所属");
      //
      catDataSet.addValue(55,"2017","都民");
      catDataSet.addValue(23,"2017","自民");
      catDataSet.addValue(23,"2017","公明");
      catDataSet.addValue(19,"2017","共産");
      catDataSet.addValue( 5,"2017","民進");
      catDataSet.addValue( 1,"2017","ネット");
      catDataSet.addValue( 1,"2017","その他");
    }
    // XAxis ⇒ CategoryAxis
    CategoryAxis xAxis = new CategoryAxis("政党");
    // YAxis ⇒ NumberAxis
    NumberAxis yAxis = new NumberAxis("議席数");
    // 棒グラフで表示するのでBarRendererを使用する
    BarRenderer renderer = new BarRenderer();
    // Plotを生成して表示する
    CategoryPlot catPlot = new CategoryPlot(catDataSet,xAxis,yAxis,(CategoryItemRenderer)renderer);
    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?