1
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-複数値チャート-DefaultMultiValueCategoryDataset

Posted at

目次 ⇒ JFreeChartサンプル

package jp.avaj.lib.chart;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

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.ScatterRenderer;
import org.jfree.data.statistics.DefaultMultiValueCategoryDataset;

/**
■ JFreeChart-複数値チャート-DefaultMultiValueCategoryDataset
・同一キーに複数の値があるDataset.
・ScatterRendererで表示する

 */
public class Chart13_00 {
  // 目次-DefaultMultiValueCategoryDatasetを利用したチャート
  A_Chart13 a_Chart13;
  // 目次-Artery-JFreeChart用のライブラリ
  A_Chart00 a_LibChartSampeContents;

  public static void main(String[] args) {
    // 表示データの作成
    DefaultMultiValueCategoryDataset dataSet = null;
    {
      final int ROW = 3;
      final int COL = 4;
      Random ran = new Random();
      dataSet = new DefaultMultiValueCategoryDataset();
      List<Double> list;
      for (int row=0; row<ROW; row++) {
        for (int col=0; col<COL; col++) {
          list = new ArrayList<Double>();
          for (int i=0; i<3; i++) {
            list.add((double)ran.nextInt(100));
          }
          dataSet.add(list,"ROW"+row,"COL"+col);
        }
      }
    }
    // 軸の設定
    CategoryAxis xAxis = new CategoryAxis("商品");
    NumberAxis yAxis = new NumberAxis("売上");
    // レンダラの設定
    ScatterRenderer renderer = new ScatterRenderer();
    // Plotの作成
    CategoryPlot plot = new CategoryPlot(dataSet,xAxis,yAxis,renderer);
    //
    JFreeChart jfreeChart = new JFreeChart("ScatterRenderer",(Plot)plot);
    ChartFrame cFrame = new ChartFrame("ScatterRenderer",(JFreeChart)jfreeChart);
    cFrame.pack();
    cFrame.setVisible(true);
  }
}

無題.png

1
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
1
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?