Hi,
Two issues:
1. The plotxy X-Function will create a new graph by default. If you want to get the fitted data plotted to the original graph, you have to specify the target graph to plot the fitted data.
2. There is a syntax mistake in this line, "=" is missing.
LT_execute("plotxy iy:=(1,2) plot:200");
I change your code like below, and it is able to plot the fitted data to the original graph.
void PlotFitXY(int NUMB)
{
for(int i=1;i<=NUMB;i++)
{
WorksheetPage WSP= Project.WorksheetPages.Item(i);
Worksheet ws = WSP.Layers(0);
set_active_layer(ws);
LT_execute("plotxy iy:=(1,2) plot:=200");
// Get the graph
GraphPage gp = Project.ActiveLayer().GetPage();
if(!gp)
return;
bool bInit;
Operation& op = (Operation&)op_create("FitNL", bInit); // the operation name of NLFit is FitNL
if( !bInit )
{
out_str("Error in op create");
return;
}
Tree trOp;
op.GetTree(trOp);
if( !ws )
return;
DataRange dr;
dr.Add(ws, 0, "X");
dr.Add(ws, 1, "Y");
// init trOp.GUI.InputData treenodes from dr and do SetData, SetFunction actions
string strFunction = "ExpDec3";
string strCategory = "Exponential";
if (OP_NOERROR != op.OnInitDataFromOCLT(trOp, trOp.GUI.InputData, dr, strFunction, strCategory) )
{
out_str("Fail to init data from data range");
return;
}
op.SetTree(trOp);// set the changes of trOp back to op object
int nAutoUpdate = AU_AUTO;
op.OnNoEdit(0, nAutoUpdate);
op.Execute(); // do fit and genereate report
Worksheet wsp = WSP.Layers(2);
set_active_layer(wsp);
// Correct the syntax issue, and specify where to plot the fitted data
LT_execute("plotxy iy:=(1,2) plot:=200 ogl:=[" + gp.GetName() + "]1!");
}
}
Penn