DataRange::SetRange
SetRange
Description
Set the subrange at the given index.
Syntax
BOOL SetRange( int nIndex, Datasheet & ds, int nR1, int nC1, int nR2, int nC2, LPCSTR lpcszName = NULL )
Parameters
- nIndex
- [input]Index of the range to modify
- ds
- [input]Worksheet or MatrixLayer in which range reside
- nR1
- [input]Row range begin
- nC1
- [input]Column range begin
- nR2
- [input]Row range end, use -1 to indicate end of column
- nC2
- [input]Column range end, if only one column then put in same value as nC1, if to end of worksheet use -1
- lpcszName
- [input]Name of the range to add. If NULL the old name will be left unchanged. To create a range for plotting then
- use "X", "Y", "Z", or "ED" for Y error bars.
Return
Returns TRUE on successful exit and FALSE on failure.
Examples
EX1
// Draw two dataplots using the data in the worksheet as XYY.
void DataRange_SetRange_Ex1(int nXCol = 0, int nYCol = 1, int nPlots = 1)
{
//Create a worksheet with three columns and fill with data.
Worksheet wks;
wks.Create("Origin");
if( !wks )
return;
while(wks.Columns(0))
wks.DeleteCol(0);
int nColIndex =0;
for(int n=0; n< nPlots +2; n++)
nColIndex = wks.AddCol();
for(int i=0;i<nPlots+2;i++)
{
for (int j=0;j<10;j++)
{
double rr=rnd();
wks.SetCell(j,i,rr*100);
}
}
//Create a datarange with two subranges X and Y.
DataRange dr;
dr.Add(wks, nXCol, "A");
dr.Add(wks, nYCol, "B");
dr.SetRange(0, wks, 0, nXCol, -1, nXCol, "X"); // Rename range to X for plotting
dr.SetRange(1, wks, 0, nYCol, -1, nYCol, "Y"); // Rename range to Y for plotting
GraphPage gp;
gp.Create("Origin", CREATE_HIDDEN);
if( gp )
{
GraphLayer gl = gp.Layers();
if( gl )
{
int nPlotIndex, iColor;
iColor = 0; // Index in Origin color list 0=Black, 1=Red, etc.
DataPlot dp;
for(int ii = 0; ii < nPlots+1; ii++)
{
dr.SetRange(1, wks, 0, nYCol + ii, -1, nYCol + ii, NULL); // Change Y range but do not rename
nPlotIndex = gl.AddPlot(dr, IDM_PLOT_SCATTER);
dp = gl.DataPlots(nPlotIndex);
if( dp )
dp.SetColor(iColor++, TRUE ); // Set color of current DataPlot
}
gl.Rescale();
gp.SetShow();
}
}
}
Remark
Set the subrange at the given index. The subrange at the given index must exist.
See Also
DataRange::Add, DataRange::AddInput
header to Include
origin.h
|