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-平均と標準偏差のチャート-DefaultStatisticalCategoryDataset

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.StatisticalBarRenderer;
import org.jfree.data.statistics.DefaultStatisticalCategoryDataset;

/**
■ JFreeChart-平均と標準偏差のチャート-DefaultStatisticalCategoryDataset
・レンダラにはStatisticalBarRendererを使用する

 */
public class Chart12_01 {
  // 目次-平均と標準偏差のチャート-DefaultStatisticalCategoryDataset
  A_Chart12 a_Chart12;
  // 目次-Artery-JFreeChart用のライブラリ
  A_Chart00 a_LibChartSampeContents;

  public static void main(String[] args) {
    // 表示データの作成
	  DefaultStatisticalCategoryDataset dataSet = new DefaultStatisticalCategoryDataset();
    {
      // 日ごとの売り上げの平均
      final double[][] means =  {
        {50,30,34,33,60}, // 1-3
        {55,40,45,37,60}  // 4-6
      };
      // 日ごとの売り上げの標準偏差
      final double[][] devis = {
        {5,2,4,3,5}, // 1-3
        {4,3,3,5,6}, // 4-6
      };
      // 商品名
      final String[] catKeys = {"A","B","C","D","E"};
      // 期間
      String[] serKeys = new String[]{"1月~3月","4月~6月"};
      // データを設定する
      for (int i=0; i<serKeys.length; i++) {
        for (int j=0; j<catKeys.length; j++) {
          dataSet.add(means[i][j],devis[i][j], serKeys[i],catKeys[j]);
        }
      }
    }
    // 軸の設定
    CategoryAxis xAxis = new CategoryAxis("商品");
    NumberAxis yAxis = new NumberAxis("売上");
    // レンダラの設定
    StatisticalBarRenderer renderer = new StatisticalBarRenderer();
    // Plotの作成
    CategoryPlot plot = new CategoryPlot(dataSet,xAxis,yAxis,renderer);
    //
    JFreeChart jfreeChart = new JFreeChart("売上の平均と標準偏差",(Plot)plot);
    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?