
// XYLogAxisEx.java
// http://www.java2s.com/Code/Java/Chart/JFreeChartXYLogAxesDemo.htm
// Modified by Andrew Davison, ad@coe.psu.ac.th, Nov 2022


/* Three exponential lines in a XY Line Chart, 
   with data points stored as (x,y) values in a XYSeries.

   The y-axis is a log scale, so the lines are drawn
   linearly.
  
    Usage:
      > compile XYLogAxisEx.java
      > run XYLogAxisEx
*/

import java.awt.*;
import javax.swing.*;

import org.jfree.chart.*;
import org.jfree.chart.axis.*;
import org.jfree.chart.plot.*;

import org.jfree.data.xy.*;



public class XYLogAxisEx extends JFrame
{

  public XYLogAxisEx()
  {
    super("Y Log Axis Example");

    XYSeriesCollection ds = createDataset();
    JFreeChart chart = createChart(ds);

    ChartPanel cp = new ChartPanel(chart);
    setContentPane(cp);

    // pack()
    setSize(800, 400);
    setResizable(false);
    setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    setLocationRelativeTo(null);
    setVisible(true);
  }  // end of XYLogAxisEx()


  private XYSeriesCollection createDataset()
  // three series of points from an exponential function
  {
    XYSeries s1 = new XYSeries("Series 1");
    XYSeries s2 = new XYSeries("Series 2");
    XYSeries s3 = new XYSeries("Series 3");

    for (int i = 1; i <= 50; i++) {
      s1.add(i, 10 * Math.exp(i / 5.0));
      s2.add(i, 20 * Math.exp(i / 5.0));
      s3.add(i, 30 * Math.exp(i / 5.0));
    }

    XYSeriesCollection ds = new XYSeriesCollection();
    ds.addSeries(s1);
    ds.addSeries(s2);
    ds.addSeries(s3);

    return ds;
  } /* createDataset */



  private JFreeChart createChart(XYSeriesCollection ds)
  {
    JFreeChart chart = ChartFactory.createXYLineChart(
         "Y Log Axis Example", "X", "Value", ds);

    XYPlot plot = chart.getXYPlot();
    plot.setRangeAxis( new LogarithmicAxis("Log(y)"));

    return chart;
  } /* createChart */


  // ----------------------------------------

  public static void main(final String[] args)
  {    new XYLogAxisEx();  } 

}  // end of XYLogAxisEx class