/*------------------------------------------------------------------------------*
 * File Name:				 													*
 * Creation: 																	*
 * Purpose: OriginC Source C file												*
 * Copyright (c) ABCD Corp.	2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010		*
 * All Rights Reserved															*
 * 																				*
 * Modification Log:															*
 *------------------------------------------------------------------------------*/
 
////////////////////////////////////////////////////////////////////////////////////
// Including the system header file Origin.h should be sufficient for most Origin
// applications and is recommended. Origin.h includes many of the most common system
// header files and is automatically pre-compiled when Origin runs the first time.
// Programs including Origin.h subsequently compile much more quickly as long as
// the size and number of other included header files is minimized. All NAG header
// files are now included in Origin.h and no longer need be separately included.
//
// Right-click on the line below and select 'Open "Origin.h"' to open the Origin.h
// system header file.
#include <Origin.h>
////////////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////////////////
// Include your own header files here.


////////////////////////////////////////////////////////////////////////////////////
// Start your functions here.

//Generate some data in worksheet, and plot it out

void GenerateDataToWorkSheetAndPlot()
{
	WorksheetPage wp;	//create WorksheetPage
	wp.Create();
	
	Worksheet wks = wp.Layers(0);   //get the first Layer
	
	wks.SetName("Data");		//set Layer name
	
	int nRowSize = 2;			//set the wks size
	int nColSize = 20;
	wks.SetSize(nRowSize, nColSize);

	//generate data to col1 and col2;
	vector vX, vY;		
	
	XYRange dr;								//set the XYRange
	dr.Add(wks, 0, "X");                   
	dr.Add(wks, 1, "Y");
	
	for (int i = 0; i < nColSize; i++)			//Generate random data vector
    {
           double rr = rnd();
           vX.Add(rr);
           
           rr = rnd();
           vY.Add(rr);
    }
    
    vX.Sort(SORT_ASCENDING);				//sort the vector data x, y 
    vY.Sort(SORT_ASCENDING);
    
    dr.SetData(&vY, &vX);					//put the vector vX, vY, to XYRange dr
     
  	GraphPage gp;							//create new graph page							
    gp.Create();
    
    GraphLayer gl;							//create new layer on the page
    gl = gp.Layers(0);
    
    int nIndex = 0;
    DataPlot dp = dr.MakePlot(gl,NULL, nIndex);		//make plot by the XYRange;
    gl.Rescale();	//refresh the layer.
}