/*------------------------------------------------------------------------------* * File Name: AddEditTextLabelInGraph.c * * Creation: ER, 03/17/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 create a Doulbe Y graph using the corresponding // template in Origin. // // Note: // 1. It is assumed that a worksheet with three columns X, Y, Y is active // 2. Before compile this file, need run "run.LoadOC(Originlab\graph_utils.c, 16)" // to build it into current workspace, else will get linking error. // #include <..\Originlab\graph_utils.h> // needed for page_add_layer function void create_doubley_graph() { // Declare worksheet and check validity Worksheet wks = Project.ActiveLayer(); if( !wks ) { out_str("Active layer is not a worksheet!"); return; } // Declare two curves using cols 1-2 and cols 1-3 for the two Ys Curve crv1(wks, 0, 1); Curve crv2(wks, 0, 2); // If either curve is not a valid object, print error and return if(!crv1 || !crv2) { printf("Invalid curve object(s)!\n"); return; } // Create new graph page using the DoubleY template GraphPage gpg; gpg.Create("DOUBLEY"); // Declare graph layers 1 and 2 GraphLayer gly1 = gpg.Layers(0); GraphLayer gly2 = gpg.Layers(1); // Add curve 1 to layer 1 and curve 2 to layer 2, and rescale both gly1.AddPlot(crv1); gly1.Rescale(); gly2.AddPlot(crv2); gly2.Rescale(); } ///////////////////////////////////////////////////////////////////////////////// // This example shows how to create a Double(or more) Y graph not using the template. // // Note: It is assumed that a worksheet with at least three columns X, Y, Y(or more Y) // is active. // void create_multiy_graph() { // Construct data range from active worksheet Worksheet wks = Project.ActiveLayer(); DataRange dr; dr.Add(wks, 0, "X"); // 1st column as X data dr.Add(wks, 1, "Y", -1); // Others column as Y data // Get the number of Y DWORD dwRules = DRR_GET_DEPENDENT | DRR_NO_FACTORS; int nNumYs = dr.GetNumData(dwRules); // Add more layers with right Axis and link to the 1st layer GraphPage gp; gp.Create("Origin"); while ( gp.Layers.Count() < nNumYs ) { page_add_layer(gp, false, false, false, true, ADD_LAYER_INIT_SIZE_POS_MOVE_OFFSET, false, 0, LINK_STRAIGHT); } // Loop and add plot from each XY data range to graph layer foreach(GraphLayer gl in gp.Layers) { int nLayerIndex = gl.GetIndex(); // Get the sub XY range from dr DataRange drOne; dr.GetSubRange(drOne, dwRules, nLayerIndex); // Plot one XY range to one graph layer int nPlot = gl.AddPlot(drOne, IDM_PLOT_LINE); if( nPlot >= 0 ) { DataPlot dp = gl.DataPlots(nPlot); dp.SetColor(nLayerIndex); // Set make data plot as different color // Set the ticks and ticklabels of right Y axis auto color gl.YAxis.AxisObjects(AXISOBJPOS_AXIS_SECOND).RightTicks.Color.nVal = gl.YAxis.AxisObjects(AXISOBJPOS_LABEL_SECOND).RightLabels.Color.nVal = INDEX_COLOR_AUTOMATIC; gl.Rescale(); } } } /////////////////////////////////////////////////////////////////////////////////