/*------------------------------------------------------------------------------* * 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 add and change properties of a text label in a graph. // NOTE: It is assumed that a graph layer is active. // void add_edit_text_label_in_graph() { // Declare graph layer using active layer GraphLayer gly = Project.ActiveLayer(); if( !gly ) { out_str("Active layer is not a graph!"); return; } // Note: Labels can exist in pages such as worksheet as well // This example just works with graph layer // Declare graph object in OC using name of the label GraphObject grobj; // Create a new label object string strLabelName = "MyTextLabel"; grobj = gly.CreateGraphObject(GROT_TEXT, strLabelName); // Can now assign text value to label such as: grobj.Text = "This is my text"; // Can use formatting in text string such as to make multiline label: string strLabelText; double dVal1 = 10.3, dVal2 = 0.035; strLabelText.Format("Value 1 = \t%e\nValue 2 = \t%e", dVal1, dVal2); grobj.Text = strLabelText; // Can change other properties of label as well. // To see properties, can get into tree and dump to script window Tree tr; tr = grobj.Label; out_str("Label Properties:"); out_tree(tr); // Once you know what properties are available, can set them: grobj.Label.Font.Size.nVal = 30; grobj.Label.Color.nVal = 1; grobj.Label.Angle.nVal = 45; grobj.Label.Dimension.Left.dVal = 0; grobj.Label.Dimension.Top.dVal = 5; gly.GetPage().Refresh(); } /////////////////////////////////////////////////////////////////////////////////