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-SymbolAxis,StepRender

Posted at

目次 ⇒ JFreeChartサンプル

package jp.avaj.lib.chart;

import java.io.IOException;

import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.axis.SymbolAxis;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.plot.Plot;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYStepRenderer;
import org.jfree.data.Range;
import org.jfree.data.xy.DefaultXYDataset;
import org.jfree.data.xy.XYDataset;

/**
■ JFreeChart-SymbolAxis,StepRender

・Y軸は最小値:0、最大値:5で、0の場合をA、5の場合をFと表示する.
・今回はY軸をシンボルとしたが、X軸でも同様のことができる.

・データ値が離散値なのでStepRendererを使用して描画する

 */
public class Chart18_05 {
  // 目次-ガAxis,目盛、グリッド.
  A_Chart18 a_Chart18;
  // 目次-Artery-JFreeChart用のライブラリ
  A_Chart00 a_LibChartSampeContents;

  public static void main(String[] args) throws IOException {
    DefaultXYDataset dataSet = new DefaultXYDataset();
    double[][] data = createData();
    dataSet.addSeries("ステップ",data);
    //
    // SymbolAxisを生成してデータ範囲を割り当てる
    SymbolAxis yAxis = new SymbolAxis("symbol",new String[]{"A","B","C","D","E","F"}); // (1)
    yAxis.setRange(new Range(0,5));
    //
    NumberAxis xAxis = new NumberAxis();
    // 離散値なのでStepRenderを使用する
    XYStepRenderer renderer = new XYStepRenderer();
    // チャートを表示する
    XYPlot xyPlot = new XYPlot((XYDataset)dataSet,(ValueAxis)xAxis,(ValueAxis)yAxis,renderer);
    JFreeChart jfreeChart = new JFreeChart("SymbolAxis",(Plot)xyPlot);
    ChartFrame cFrame = new ChartFrame("SymbolAxis",(JFreeChart)jfreeChart);
    cFrame.pack();
    cFrame.setVisible(true);
  }
  // 1~4のデータを生成する
  private static double[][] createData() {
    int COUNT = 10;
    int MIN = 1;
    int MAX = 4;
    double[] x = new double[COUNT];
    double[] y = new double[COUNT];
    int value = MIN;
    for (int i=0; i<COUNT; i++) {
      x[i] = (double)i;
      y[i] = (double)value;
      value++;
      if (value > MAX) {
        value = MIN;
      }
    }
    return new double[][]{ x,y };
  }
}

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