/**********************************************************************
# Copyright (c) EWA Systems Inc. 1998 - 2005 All Rights Reserved
#               No part of this program may be photocopied, reproduced,
#               or translated to another programming language without
#               the prior written consent of EWA Systems.
**********************************************************************/

package com.ewasystems.chart.test;

import java.awt.Color;
import com.ewasystems.chart.AxesXY;
import com.ewasystems.chart.Chart;
import com.ewasystems.chart.ChartData;
import com.ewasystems.chart.ChartLegend;
import com.ewasystems.chart.ChartText;
import com.ewasystems.chart.JFrameChart;

/**
 * <p>Title: Example Area Chart</p>
 * <p>Copyright: (c) 1998 - 2005</p>
 * <p>Company: EWA Systems, Inc.</p>
 * @author Lincoln Evans-Beauchamp
 * @version 1.0
 */

public class AreaEx1
{
  static private void setup(Chart chart)
  {
    AxesXY axis = new AxesXY(chart);
    int npoints = 20;
    double dx = .5 * Math.PI/(npoints - 1);
    double x[]  = new double[npoints];
    double y1[] = new double[npoints];
    double y2[] = new double[npoints];
    double y3[] = new double[npoints];
    //  Generate some data
    for (int i = 0;  i < npoints;  i++)
    {
      x[i] = i * dx;
      y1[i] = Math.sin(x[i]);
      y2[i] = Math.cos(x[i]);
      y3[i] = Math.atan(x[i]);
    }
    ChartData d1 = new ChartData(axis, x, y1);
    ChartData d2 = new ChartData(axis, x, y2);
    ChartData d3 = new ChartData(axis, x, y3);
    //  Set Data Type to Fill Area
    axis.setDataType(d1.DATA_TYPE_FILL);
    //  Set Line Colors
    d1.setLineColor(Color.red);
    d2.setLineColor(Color.black);
    d3.setLineColor(Color.blue);
    //  Set Fill Colors
    d1.setFillColor(Color.red);
    d2.setFillColor(Color.black);
    d3.setFillColor(Color.blue);
    //  Set Data Labels
    d1.setTitle( "Sine" );
    d2.setTitle( "Cosine" );
    d3.setTitle( "ArcTangent" );
    //  Add a Legend
    ChartLegend legend = chart.getChartLegend();
    legend.setTitle(new ChartText( "Legend" ));
    legend.setPaint(true);
    //  Set the Chart Title
    chart.getChartTitle().setTitle( "Area Plots" );
  }

  public static void main(String args[])
  {
    try
    {
      JFrameChart frame = new JFrameChart();
      AreaEx1.setup(frame.getChart());
      frame.show();
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
  }
}
