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/二次元分布チャート/XYSeriesCollection

Posted at

目次 ⇒ JFreeChartサンプル

package jp.avaj.lib.chart;

import java.util.Random;

import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.Plot;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYItemRenderer;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;

/**
■ JFreeChart/二次元分布チャート/XYSeriesCollection

 */
public class Chart15_00 {

  public static void main(String[] args) {
    // 表示データの作成
    XYSeriesCollection collection = createXYDataset();
    // レンダラの指定
    // 最初の引数はラインを引くかどうか⇒今回はラインは引かない
    // 次の引数はデータの場所に形を表示するか否か⇒今回は形を表示する.
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(false,true);
    // 軸は両方ともNumberAxisにする
    NumberAxis xAxis = new NumberAxis();
    NumberAxis yAxis = new NumberAxis();
    // Plotの作成
    XYPlot xyPlot = new XYPlot((XYDataset)collection,xAxis,yAxis,(XYItemRenderer)renderer);
    // 画面表示
    JFreeChart jfreeChart = new JFreeChart("XYPlot",(Plot)xyPlot);
    ChartFrame cFrame = new ChartFrame("XYPlot",(JFreeChart)jfreeChart);  // (1)
    cFrame.pack();
    cFrame.setVisible(true);
  }

  public static XYSeriesCollection createXYDataset() {
    XYSeriesCollection xySeriesCollection = new XYSeriesCollection();
    Random ran = new Random();
    for (int series = 0; series<5; series++) {
      XYSeries xySeries = new XYSeries("data-" + series);
      for (int item = 0; item<20; item++) {
        double x = ran.nextDouble()*10;
        double y = x+ran.nextDouble()*5;
        xySeries.add(x,y);
      }
      xySeriesCollection.addSeries(xySeries);
    }
    return xySeriesCollection;
  }
}

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