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-NumberAxis-目盛りの間隔の設定

Last updated at Posted at 2019-07-13

目次 ⇒ JFreeChartサンプル

package jp.avaj.lib.chart;

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

import jp.avaj.lib.algo.ArUtil;

/**
■ JFreeChart-NumberAxis-目盛りの間隔の設定

 */
public class Chart18_00 {

  public static void main(String[] args) {
    // 表示データを生成
    XYDataset dataset = createDataset();
    // 軸を生成
    ValueAxis xAxis = new NumberAxis();
    ValueAxis yAxis = new NumberAxis();
    // レンダラ ⇒ これが全体のレンダラになる
    XYItemRenderer renderer = new StandardXYItemRenderer();
    // Plotを生成してチャートを表示する
    XYPlot xyPlot = new XYPlot(dataset,xAxis,yAxis,renderer);
    JFreeChart jfreeChart = new JFreeChart("Unit-Tick",(Plot)xyPlot);
    ChartFrame cFrame = new ChartFrame("Unit-Tick",(JFreeChart)jfreeChart);
    cFrame.pack();
    cFrame.setVisible(true);



    // y軸の目盛りを設定する
    {
      // 目で確認するために少し休む
      ArUtil.sleep(4000);
      // y軸の目盛りを設定する
      // 複数個設定できる⇒拡大した時は、細かいものが使用される
      TickUnits ty = new TickUnits();
      ty.add(new NumberTickUnit(2.0));
      ty.add(new NumberTickUnit(0.5));
      yAxis.setStandardTickUnits(ty);
    }
  }

  private static XYDataset createDataset() {
    XYSeriesCollection dataset = new XYSeriesCollection();
    // 一本目
    XYSeries xySeries = new XYSeries("data-0");
    for (int j=0; j<10; j++) {
    	xySeries.add(j,j+Math.random()*4.0D);
    }
    dataset.addSeries(xySeries);
    // 二本目
    xySeries = new XYSeries("data-1");
    for (int j=0; j<10; j++) {
    	xySeries.add(j,9-j+Math.random()*4.0D);
    }
    dataset.addSeries(xySeries);
    return dataset;
  }
}

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