This page shows how to update graph legend by Origin C code.
Minimum Origin Version Required: Origin 8 SR0
This example shows how to refresh legend for active graph layer. Please follow the following steps to try.
void legend_update() { GraphLayer gl = Project.ActiveLayer(); if(!gl) { out_str("Please activate one graph layer"); return; } // no need to specified any option arguments since here just refresh legend on data plotting legend_update(gl); }
This example shows how to combine the legend from multiple layers in one page to one legend. Please follow the following steps to try.
void combile_page_legends() { GraphLayer gl = Project.ActiveLayer(); if(!gl) { out_str("Please activate one graph window"); return; } GraphPage gp = gl.GetPage(); int nMode = -1; // ignore if <0 otherwise to set the corresponding graph page's Auto Legend mode bool bCreate = true; bool bReconstruct = true; bool bOneForAll = true; // if true only create one legend for all layers bool bAscending = true; foreach (gl in gp.Layers) { legend_update(gl, nMode, bCreate, bReconstruct, NULL, bOneForAll, bAscending); } bool bCombine = true; if ( bReconstruct && bCombine) { legend_combine(gp, 0, bAscending); } }
This example functions show how to change legend mode for one graph page, not for layer. Please copy the functions below to one c file, add file to Code Builder Workspace and compile it.
There is a way to set the legend mode of one graph on GUI:
This example shows how to set legend mode to Data Range for all legends on the page of the active graph layer.
Activate one graph and then run set_page_legend_mode in Command Window, legend should display full data range of each plotting.
void set_page_legend_mode() { GraphLayer gl = Project.ActiveLayer(); if(!gl) { out_str("Please activate one graph window"); return; } legend_update(gl, ALM_RANGE); }
void set_page_legend_custom_mode() { GraphLayer gl = Project.ActiveLayer(); if(!gl) { out_str("Please activate one graph window"); return; } int nMode = ALM_CUSTOM; bool bCreate = true; // true, if no legend will create one bool bReconstruct = false; // true, if always delete the original legend and create a new one; false, not delete old one just update string strCustomMode = "@U"; // use Column Units label as legend if( legend_update(gl, nMode, bCreate, bReconstruct, strCustomMode) ) { out_str("Set layer mode successfully"); } else { out_str("Fail to set layer mode"); } }