| add_plots_to_layer  DescriptionIt adds one or more plots to a graph layer using data from a worksheet. Syntax
int add_plots_to_layer( GraphLayer & lay, int nPlotType, LPCSTR lpcszWksName, vector<string> & vsCols, vector<uint> & vpdesig, DWORD dwCntrl = DPEDTVIEW_HIDE_LIMITS )
 Parameters
    lay[input] graph layer to add the plot(s) to.nPlotType[input] plot type idlpcszWksName[input] the name of the worksheet to take the data from. It can be "[book]sheet" if workbook name is different from worksheet name.vsCols[input] vector of strings with the column names to use from the worksheet lpcszWksName when creating the plot.vpdesig[input] a vector of integers holding the column designations for each columnfrom the vector vsCols. The size of the vector vpdesig must matchthe size of the vector vsCols. The column designations must have thevalues from the following enumeration:typedef enum tagPlotDesignationEx {COLDESIG_NONE = 0,COLDESIG_X = 1,COLDESIG_Y,COLDESIG_Z,COLDESIG_ERROR_OR_LABEL_BEGIN,COLDESIG_LABEL = COLDESIG_ERROR_OR_LABEL_BEGIN,COLDESIG_XERROR,COLDESIG_YERROR,COLDESIG_YPLUSERROR,COLDESIG_ERROR_OR_LABEL_END,COLDESIG_YMINUSERROR = COLDESIG_ERROR_OR_LABEL_END,COLDESIG_SIZE, // for symbol size in bubble plotsCOLDESIG_COLOR, // for symbol color in scatter color plotsCOLDESIG_VECTOR_ANGLE, // for vector XYAM plotsCOLDESIG_VECTOR_MAGNITUDE, // for vector XYAM plotsCOLDESIG_VECTOR_XEND, // for vector XYXY plotsCOLDESIG_VECTOR_YEND // for vector XYXY plots} PlotDesignationEx;dwCntrl[input] view filter for DataPlots tree editor Return1) >0, the total number of plots added; 2) =0 means "Failed to add dataplots."; 3) =-1 means "Cannot create plot tree."; ExamplesEX1 
//        The example creates a graph with a vector XYXY plot.
//    Parameters:
//        strWksName=the name of the worksheet to take the data from.
//        strX1ColName=the name of the column for X1
//        strY1ColName=the name of the column for Y1
//        strX2ColName=the name of the column for X2
//        strY2ColName=the name of the column for Y2
void    make_XYXY(string strWksName, string strX1ColName, string strY1ColName, string strX2ColName, string strY2ColName)
{
    GraphPage   pg;
    // Create a new graph from the template appropriate for vector XYXY graphs:
    if ( !pg.Create("VectXYXY"))
    {
        out_str("Cannot create page");
        return;
    }
    
    // Get the first layer from the graph:
    GraphLayer  lay = pg.Layers(0);
    if ( !lay )
    {
        out_str("Cannot get graph layer");
        return;
    }
    
    // Build the arrays of the column names and designations.
    vector<string>      vsCols;
    vector<uint>        vpdesig;
    
    vpdesig.SetSize(4);
    vsCols.SetSize(4);
    
    vsCols[0] = strX1ColName;
    vpdesig[0] = COLDESIG_X;
    
    vsCols[1] = strY1ColName;
    vpdesig[1] = COLDESIG_Y;
    
    vsCols[2] = strX2ColName;
    vpdesig[2] = COLDESIG_VECTOR_XEND;
    
    vsCols[3] = strY2ColName;
    vpdesig[3] = COLDESIG_VECTOR_YEND;
    
    int    nNum = add_plots_to_layer(lay, IDM_PLOT_FLOWVECTOR, strWksName, vsCols, vpdesig);
    
    if (0 < nNum)
        lay.Rescale();        // rescale the layer to show all the data points
    
    return;
}
EX2 
//Workbook and worksheet names are different.
#include <..\Originlab\FileImport.h>
typedef int (*FUNC_IMP)(LPCSTR strPageName, int nIndexLayer, LPCSTR lpcszDataFile, LPCSTR lpcszFilterName = NULL);
void add_plots_to_layer_ex2()
{        
        string strPath = GetAppPath(TRUE) + "Samples\\Curve Fitting\\"; 
        Worksheet wks;
        wks.Create("origin");
        FUNC_IMP pfn = Project.FindFunction("import_file", "OriginLab\\FileImport.c", true);
        if(pfn)
                pfn(wks.GetPage().GetName(), 0, strPath + "Multiple Gaussians.DAT", "ASCII");
        
    string strBookSheet;
    wks.GetRangeString(strBookSheet, NTYPE_LAYER_NO_EXCLAMATION);
    out_str(strBookSheet);
    
    GraphPage pg;
    pg.Create("origin");
    GraphLayer  lay = pg.Layers(0);
    
    vector<string> vsCols = {"A", "B", "D"}; 
    vector<uint> vpdesig = {COLDESIG_X, COLDESIG_Y, COLDESIG_YERROR};
    add_plots_to_layer(lay, IDM_PLOT_LINESYMB, strBookSheet, vsCols, vpdesig);
    lay.Rescale();
}
RemarkSee Alsoheader to Includeorigin.h Reference |