Add a new subrange to the DataRangeEx. The subrange is specified by passing an Excel like selection string similar to "[Book1]Sheet1!A[1]:B[2]".
Add a new subrange to the DataRange. The subrange is specified using a Worksheet object and beginning
and ending row and column indices.
int Add( LPCSTR lpcszRange, LPCSTR lpcszName = NULL )
int Add( Worksheet & wks, int nR1, int nC1, int nR2, int nC2, LPCSTR lpcszName = NULL )
Returns the number of subranges in the DataRangeEx after execution.
EX1
// This example assumes a worksheet named Sheet1 having two columns named A and B containing XY data // is the active layer //Draw a scatter graph with Column A and Column B. void DataRangeEx_Add_Ex1() { double rr; Worksheet wks; wks.Create("Origin"); Page pg; pg=wks.GetPage(); if( wks ) { while(wks.Columns(0)) wks.DeleteCol(0); //Create a worksheet with two columns. wks.AddCol("A"); wks.AddCol("B"); //Fill the two columns with random data. for(int i=0;i<2;i++) { for(int j=0;j<10;j++) { rr=rnd(); wks.SetCell(j, i, 100*rr); } } //Create a DataRangeEx with A,B Columns. DataRangeEx dr; string strX,strY; strX="["+pg.GetName()+"]Sheet1!A:A"; strY="["+pg.GetName()+"]Sheet1!B:B"; dr.Add(strX, "X"); dr.Add(strY, "Y"); GraphPage gp; gp.Create("Origin", CREATE_HIDDEN); if( gp ) { GraphLayer gl = gp.Layers(); if( gl ) { //Draw a scatter plot with DataRangeEx. gl.AddPlot(dr, IDM_PLOT_SCATTER); gl.Rescale(); gp.SetShow(); } } } }
EX2
//Assume there is a worksheet which has two columns with data. //Draw a line plot with col(1) and col(2). void DataRangeEx_Add_Ex2() { Worksheet wks = Project.ActiveLayer(); //Create a DataRangeEx with xy ranges. DataRangeEx dr; dr.Add(wks, 0, 0, -1, 0, "X"); dr.Add(wks, 0, 1, -1, 1, "Y"); GraphPage gp; gp.Create("Origin", CREATE_HIDDEN); if( gp ) { GraphLayer gl = gp.Layers(); if( gl ) { //Draw a line plot with DataRangeEx. gl.AddPlot(dr, IDM_PLOT_LINE); gl.Rescale(); gp.SetShow(); } } }
DataRange::AddInput,DataRange::SetRange
origin.h