3.5.1 Axes Formatting

Version Info

Minimum Origin Version Required: Origin 8 SR0

View Axis Format Tree

To view scale, tick, tick label relative format tree.

Compile, and then run this function in Commad window will output format tree.

void ViewAxisFormatTree()
{
	GraphLayer gl = Project.ActiveLayer();
	if(!gl)
		return;
	
	Axis aX = gl.XAxis;
	if(!aX)
		return;
	
	Tree trFormat;
	trFormat = aX.GetFormat(FPB_ALL, FOB_ALL, TRUE, TRUE);
	out_tree(trFormat); // output format tree
	
	string strSaveTo = GetAppPath(false) + "AxisFormatTree.xml";
	if(trFormat.Save(strSaveTo))
		out_str("Format Tree xml file saved to "+strSaveTo);
}

Turn On Top-Right Axes

void show_top_right_axes()
{
	GraphLayer gl = Project.ActiveLayer();
	if( !gl )
		return;    
	Tree trFormat;
	// first turn on top-right axes with a separate ApplyFormat call
	trFormat.Root.Axes.X.Ticks.TopTicks.show.nVal = 1;
	trFormat.Root.Axes.Y.Ticks.RightTicks.show.nVal = 1;
	//assign node IDs to all nodes in trFormat, return number of errors
	int nErr = gl.UpdateThemeIDs( trFormat.Root ) ;
	if(0 != nErr)
		out_str("Fail to Update Theme IDs, theme tree has wrong structure");
	gl.ApplyFormat( trFormat, true, true, true );
	
	// then change settings can be done after needed axes are already turned on
		// Set the major minor ticks to In format for all XY axes
	trFormat.Root.Axes.All.Ticks.All.Major.nVal = 1;
	trFormat.Root.Axes.All.Ticks.All.Minor.nVal = 1;
		// Set the color of axes 
	trFormat.Root.Axes.All.Ticks.All.Color.nVal = SYSCOLOR_BLUE;  
	nErr = gl.UpdateThemeIDs( trFormat.Root ) ;
	if(0 != nErr)
		out_str("Fail to Update Theme IDs, theme tree has wrong structure");
	
	gl.ApplyFormat( trFormat, true, true, true ); 
}

Change Axes Titles

void ChangeAxisTitle()
{
    GraphLayer gl = Project.ActiveLayer();
    if( !gl )
        return;
    
    Tree trFormat;
    
    //Text is an embedded data member of TreeNode class, but here Text is a subnode, use AddNode to specify it's a node but not a data member
   	trFormat.Root.Axes.X.Titles.BottomTitle.AddNode("Text").strVal = "MyX_Title";
    trFormat.Root.Axes.Y.Titles.LeftTitle.AddNode("Text").strVal = "MyY_Title";
 
    int nErr = gl.UpdateThemeIDs( trFormat.Root ); //assign node IDs to all nodes in trFormat, return 0 means success
    if( 0 != nErr)
    {
        out_str("Exist invalid theme tree node in trFormat");
        return;
    }
    
    bool bRepaint = true, bRelative = true, bUndo = true;
    bool bRet = gl.ApplyFormat( trFormat, bRepaint, bRelative, bUndo ) ; //apply format to graph layer
    if( !bRet )
        out_str("Fail to update graph format!!!");
 
    return;
}

Change Ticks Style

Example 1

void AccessMajorMinorTicks()
{
    GraphLayer gl = Project.ActiveLayer();
    if( !gl )
        return;    
 
    //nVal, 0:In&Out, 1:In, 2:Out, 3:None;
    Tree trFormat;
 	trFormat.Root.Axes.X.Ticks.BottomTicks.Minor.nVal = 1; //in
   	trFormat.Root.Axes.X.Ticks.BottomTicks.Major.nVal = 0; //int & out
    
   	trFormat.Root.Axes.Y.Ticks.LeftTicks.Minor.nVal = 1;//in
   	trFormat.Root.Axes.Y.Ticks.LeftTicks.Major.nVal = 2;//out
    
    int nErr = gl.UpdateThemeIDs( trFormat.Root ) ;//assign node IDs to all nodes in trFormat, return number of errors
    if(0 != nErr)
    	out_str("Fail to Update Theme IDs");
    
    bool bRet = gl.ApplyFormat( trFormat, true, true, true ); //update graphlayer's format
    if( !bRet )
        out_str("Fail to update graph format!!!");    
}

Example 2

void ChangeTickLabelColor()
{
    GraphLayer gl = Project.ActiveLayer();
    if( !gl )
        return;
 
    Axis aX = gl.XAxis;
    if(!aX)
        return;   
 
    Tree trXFormat;
    trXFormat.Root.Labels.BottomLabels.Color.nVal = 1; //  change color to Red
    
    int nErr = aX.UpdateThemeIDs( trXFormat.Root ) ;//assign node IDs to all nodes in trFormat, return number of errors
    if(0 != nErr)
    	out_str("Fail to Update Theme IDs");

    bool bUndo = true;
    bool bRet = aX.ApplyFormat( trXFormat, true, true, bUndo); 
    if( !bRet )
        out_str("fail to apply format");       
}

Modify Number of Ticks

void ModifyTicksNumber()
{
    GraphLayer gl = Project.ActiveLayer();
    if( !gl )
        return; 
 
    Tree trFormat;
    trFormat.Root.Axes.X.Scale.MinorTicksCount.nVal = 3; // auto add nodes and assign 3 to MinorTicksCount    
    
    if(0 == gl.UpdateThemeIDs( trFormat.Root ) )//assign node IDs to all nodes in trFormat
    {
    	bool bRepaint = true;
    	bool bRelative = true;
    	bool bUndo = true;
        bool bRet = gl.ApplyFormat(trFormat, bRepaint, bRelative, bUndo); //update graphlayer's format
        if( !bRet )
            out_str("Fail to update graph format!!!");
    }
    return;
}

Access Radar/Spider Chart Axes Format

To run the following example, please make a radar/spider chart activated first.

void AccessRadarSpiderChartAxesFormat()
{
	GraphLayer gl = Project.ActiveLayer();
	if(!gl)
		return;
	
	// * Get format tree of graph layer
	Tree tr;
	tr = gl.GetFormat(FPB_ALL, FOB_ALL, true, true);  // Get format tree
	// Output the format tree, and there will be a node named NewAxes
	// This node includes the axis properties of the radar chart axes
	//out_tree(tr);  
	
	// * Get number of axes 
	TreeNode tnAxes;
	tnAxes = tr.Root.NewAxes;  // Get the NewAxes node
	int nCount = tnAxes.Children.Count();  // Number of axes
	printf("The number of axes in the active radar chart is %d\n", nCount);
	
	// * Loop all axes by using foreach
	foreach(TreeNode childNode in tnAxes.Children)
	{
		out_str(childNode.tagName);  // Output the tag name of the child node
	}
	
	// * Get/Set one axis' format
	// If don't know what format is available, 
	// just output the format tree to view all properties, 
	// by using out_tree(tr) like above
	// Here we are going to set the properties of 1st axis
	TreeNode tnAxis1;
	tnAxis1 = tnAxes.NewAxis1;  // Get the first axis node
	tnAxis1.Line.Color.nVal = 1;  // Axis color = red
	tnAxis1.Scale.From.dVal = 10.0;  // Axis from = 10.0
	tnAxis1.Scale.To.dVal = 30.0;  // Axis to = 30.0
	tnAxis1.Scale.IncrementBy.nVal = 0;  // Major ticks by increment
	tnAxis1.Scale.Value.dVal = 5.0;  // Increment by 5.0
	tnAxis1.Title.Color.nVal = 1;  // Change the axis title color to red
	if(0 == gl.UpdateThemeIDs(tr.Root))
		if(!gl.ApplyFormat(tr, true, true))
			out_str("Failed to apply format");
}