DataRange
DataRange-Class
Name
DataRange
Remark
The DataRange class provides methods and properties to construct data ranges for getting and putting data from and to a Worksheet, Matrix and Graph window. This class itself does not contain data; it just keeps the data range with the page name, sheet name (layer index for graph) and row/column indices (data plot index for graph). One DataRange object can contain multiple data ranges. The sub data range can be a whole data sheet, one column or row, or multiple continuous columns or rows.
Hierarchy
Examples
EX1
// plotting multiple columns in a group plot with X column from the end
void DataRange_ex1()
{
Worksheet wks;
wks.Create("Origin");
int nCols = 5;
int nRows = 100;
wks.SetSize(nRows, nCols);
// for a demo, lets use the last col as X
int nX = nCols-1;
Dataset dx(wks, nX);
dx.Data(1, nRows);
// fill the Y cols (even though 1st col is really X in the wks, we will plot it as Y anyway)
for(int nC = 0; nC < nCols-1; nC++)
{
Dataset dy(wks, nC);
dy.Normal(nRows);
dy += nC * 2;
}
//now we will construct our data range with all the Y columns to plot againt the X column at the end of the worksheet
DataRange dr;
dr.Add(wks, nX, "X");
for(int ii = 0; ii < nCols-1; ii++)
dr.Add(wks, ii, "Y");
GraphPage gp;
gp.Create("Origin", CREATE_HIDDEN);
GraphLayer gl = gp.Layers();
gl.AddPlot(dr, IDM_PLOT_LINE);
gl.Rescale();
gp.SetShow();
// you can verify that all the plots are plotting againt the last col as X even though the worksheet is having 1st col as X
}
EX2
// This example prints out the minimum and maximum X and Y values in all existing
// XY selections of the active worksheet or graph
// you can make the plot from example code above, or from any existing plot
// if you do not make a selection, then the whole active plot is considered selected,
// otherwise you can use the Regional Selection tool to select multiple regions
void DataRange_ex2()
{
Tree trXYSelection;
DWORD dwRules = DRR_GET_DEPENDENT | DRR_NO_FACTORS;
init_input_data_branch_from_selection(trXYSelection, dwRules);
// out_tree(trXYSelection);
DataRange dr;
dr.Create(trXYSelection, false);
DWORD dwPlotID; // This is to retrieve DataPlot UID if present
vector vX, vY;
double xmin, xmax, ymin, ymax;
string strRange;
int nNumRanges = dr.GetNumData(dwRules);
for( int nIndex = 0; nIndex < nNumRanges; nIndex++ )
{
// Copy data associated with nIndex of dr into vectors using DataRange::GetData
dr.GetData( dwRules, nIndex, &dwPlotID, NULL, &vY, &vX);
// Now we have made a copy of XY data into vectors vX and vY
// so we can do analysis on the data...for example:
vX.GetMinMax(xmin, xmax);
vY.GetMinMax(ymin, ymax);
DataRange drSub;
dr.GetSubRange(drSub, dwRules, nIndex);
strRange = drSub.GetDescription();
printf("%s\nxmin = %g\nxmax = %g\nymin = %g\nymax = %g\n", strRange, xmin, xmax, ymin, ymax);
}
}
EX3
//strX,Y are col names
//call XF to integrate an area using data from active book, given sheet name
#include <XFbase.h>
void DataRange_ex3(string strX, string strY, string strSheet)
{
Worksheet wks = Project.ActiveLayer();
wks.AddCol();
wks.AddCol();
//Create input datarange.
DataRange dr1;
string strRange;
strRange.Format("%s!(%s,%s)", strSheet, strX, strY);
dr1.Create(strRange, XVT_XYDATARANGE);
//Created output datarange.
DataRange dr2;
dr2.Add(wks, 2, "X");
dr2.Add(wks, 3, "Y");
XYRange yi(dr1);
//integ1 -h to see usage of this XF
XFBase xf("integ1");
XYRange yo(dr2);
xf.SetArg("iy", yi);
xf.SetArg("oy", yo);// to make it <optional>
double dArea;
xf.SetArg("area", dArea);
if ( !xf.Evaluate() )
out_str("failed to execute XF");
else
printf("for XY Data %s\narea = %g\n", yi.GetDescription(), dArea);
}
header to Include
origin.h
Reference
Members
|