Project::AddDataRange

Description

Add a datarange object to project that can be stored for later usage

Syntax

int AddDataRange( DataRange & rg )

Parameters

rg
[output]stored for the later usage

Return

Examples

EX1

// This shows how to associate a DataRange object with a plot...the example
// assumes an active worksheet with 30 rows of XY data in columns A and B
#include <Range.h>
void Project_AddDataRange_ex1(string strX = "Col(A)", string strY = "Col(B)", int r1 = 5, int r2 = 25)
{
    Tree tr;
    Worksheet wks = Project.ActiveLayer();
    if( wks )
    {
        // Construct DataRange tree
        construct_one_data_range(tr, wks, strX, strY, NULL, NULL, true);
        //out_tree(tr);
 
        DataRange dr;
        dr.Create(tr, true); // Default, only one range
 
        // Plot DataRange
        GraphPage gp;
        GraphLayer gl;
        gp.Create("Origin", CREATE_HIDDEN);
        if( gp )
        {
            gl = gp.Layers();
            if( gl )
            {
                gl.AddPlot(dr, IDM_PLOT_LINE);
                gl.Rescale();
                gp.SetShow();
            }
 
            DataPlot dp = gl.DataPlots(-1);
            if( dp )
            {
                uint nPlotUID = dp.GetUID(TRUE);
                //out_int("\tPlot UID = ", nPlotUID);
 
                strX.Format("[%s]%s!%s[%d:%d]", wks.GetPage().GetName(), wks.GetName(), strX, r1, r2);
                strY.Format("[%s]%s!%s[%d:%d]", wks.GetPage().GetName(), wks.GetName(), strY, r1, r2);
                // Add DataRange to Project.
                Project.AddDataRange(dr);
                dr.AddInput(strX, strY, NULL, NULL, NULL, NULL, nPlotUID);
                gp.Refresh();
                // The plot will show the range data
            }
        }
    }
}

Remark

See Also

Project::GetDataRange, Project::RemoveDataRange, DataRange::AddInput

header to Include

origin.h