/*------------------------------------------------------------------------------* * File Name: AddPlotsToLayerAndGroup.c * * Creation: ER, 02/11/05 * * Purpose: Programming Example * * Copyright (c) OriginLab Corp.2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 * * All Rights Reserved * * * * Modification Log: * *------------------------------------------------------------------------------*/ #include //////////////////////////////////////////////////////////////////////////////////// // This example shows how to add a few new plots to an existing graph layer and // then group the newly added plots. // Call this function with a graph that already has some (grouped) data plots // void add_plots_to_layer_and_group() { // Work with the active graph GraphLayer gly = Project.ActiveLayer(); if( !gly ) { out_str("Active layer is not a graph layer!"); return; } // Create a new wks and import one of the sample data files string strFile = GetAppPath(true) + "Samples\\Curve Fitting\\Exponential Decay.dat"; if( !strFile.IsFile() ) { printf("File %s is not exist.\n", strFile); return; } WorksheetPage wpg; wpg.Create("Origin"); Worksheet wks = wpg.Layers(0); wks.ImportASCII(strFile); // Add only the columns you want to add. // For example, add the 2nd and 4th column // First need to create curve objects Curve crv1(wks, 1); Curve crv2(wks, 3); if( !crv1 || !crv2 ) { out_str("Failed to declare curve!"); return; } // Add data plots for these two curves to layer int nIndex1 = gly.AddPlot(crv1); int nIndex2 = gly.AddPlot(crv2); if( -1 == nIndex1 | -1 == nIndex2 ) { out_str("Failed to add plots to layer"); return; } // Now group the added plots gly.GroupPlots(nIndex1, nIndex2); // Rescale layer gly.Rescale(); // Refresh legend legend_update(gly); // Bring graph page to forefront in case new wks is on top of it GraphPage gpg = gly.GetPage(); gpg.SetShow(); // To add entire worksheet to graph layer, where appropriate plottable columns // will be added to layer and grouped together, use: //gly.AddPlot(wks, IDM_PLOT_LINESYMB); } ////////////////////////////////////////////////////////////////////////////////////