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-バーチャートに値を表示する

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.axis.ValueAxis;
import org.jfree.chart.labels.StandardCategoryItemLabelGenerator;
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-バーチャートに値を表示する

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

  static final String ITEM_0 = "商品0";
  static final String ITEM_1 = "商品1";
  static final String DOMAIN_0 = "地域0";
  static final String DOMAIN_1 = "地域1";
  static final String DOMAIN_2 = "地域2";

  public static void main(String[] args) {
    // 表示データを生成する
    DefaultCategoryDataset dataset = createDataset();
    // X軸
    CategoryAxis domainAxis = new CategoryAxis();
    // Y軸
    ValueAxis rangeAxis = new NumberAxis();
    // 値を表示するためにY軸を少し広げる ⇒ このくらいは自動的にやってほしい....
    rangeAxis.setUpperMargin(0.1D);

    // レンダラ
    BarRenderer renderer = new BarRenderer();
    // 以下の設定で値が表示される
    renderer.setBaseItemLabelsVisible(true);
    renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    // PlotはCategoryPlot
    CategoryPlot plot = new CategoryPlot(dataset,domainAxis,rangeAxis,(CategoryItemRenderer)renderer);
    JFreeChart jfreeChart = new JFreeChart("バーチャート",(Plot)plot);
    //
    ChartFrame cFrame = new ChartFrame("バーチャート",(JFreeChart)jfreeChart);
    cFrame.pack();
    cFrame.setVisible(true);
  }

  private static DefaultCategoryDataset createDataset() {
    DefaultCategoryDataset localDefaultCategoryDataset = new DefaultCategoryDataset();
    localDefaultCategoryDataset.addValue(100.0D,ITEM_0,DOMAIN_0);
    localDefaultCategoryDataset.addValue(44.0D,ITEM_0,DOMAIN_1);
    localDefaultCategoryDataset.addValue(93.0D,ITEM_0,DOMAIN_2);
    localDefaultCategoryDataset.addValue(80.0D,ITEM_1,DOMAIN_0);
    localDefaultCategoryDataset.addValue(75.0D,ITEM_1,DOMAIN_1);
    localDefaultCategoryDataset.addValue(15.0D,ITEM_1,DOMAIN_2);
    return localDefaultCategoryDataset;
  }
}

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