Export Graph
Version Info
Minimum Origin Version Required: Origin 8 SR1
Example
This example illustrates how to export a graph to the User Files Folder, with the "png" graph type.
To run this example, please run the following LabTalk script first to create the required graph.
// create a new workbook
newbook;
// import file path
fname$ = system.path.program$ + "Samples\Curve Fitting\Gauss Lorentz.dat";
// import
impASC;
void export_graph()
{
// get active worksheet
Worksheet wks = Project.ActiveLayer();
if (!wks) // get no worksheet
{
out_str("Failed to get active worksheet!\n");
return;
}
// set data of data range by column 1 and column 2 in worksheet
DataRange dr;
dr.Add("X", wks, 0, 0, -1, 0);
dr.Add("Y", wks, 0, 1, -1, 1);
GraphPage gp;
// create graph page
gp.Create("Origin");
// check if graph page was created
if (!gp)
{
out_str("Failed to create graph page!\n");
return;
}
// get graph layer in graph page
GraphLayer gl = gp.Layers(0);
// add plot with line type to graph layer
int nPlot = gl.AddPlot(dr, IDM_PLOT_LINE);
if (nPlot == -1)
{
out_str("Failed to add plot to graph layer!\n");
return;
}
// rescale the graph layer
gl.Rescale();
// graph page name
string strGraphPageName;
gp.GetName(strGraphPageName);
// type of exported graph
string strGraphType = "png";
// full path of the exported graph, in User Files Folder
string strGraphPath = GetAppPath(false) + strGraphPageName + "." + strGraphType;
// export the graph
bool bRet = export_page(gp, strGraphPath, strGraphType);
if (bRet == false)
out_str("Failed to export graph!\n");
}
|