Author |
Topic  |
|
a.abc.b35
175 Posts |
Posted - 05/17/2011 : 10:07:32 PM
|
Origin Ver. and Service Release (Select Help-->About Origin): 8, SR0 Operating System: Windows 7 .............. I am trying to run the following code : **code pasted at end** Now the problem is, the code runs properly, plots the graphs also but without changing the symbol shapes,sizes etc ( which I try to access by the Tree trFormat). Can someone help me here ?
#include <Origin.h>
////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
// It graphs a workbook as below:
// It takes 2 integer parameters, which are column numbers.
// 1st input column is X, 2nd is Y
////////////////////////////////////////////////////////////////////////////////////
// Start your functions here.
void GraphWorkBookXY(int ic1,int ic2)
{
// enter Workbook whose worksheets are to be graphed
string wpName = InputBox("Please enter the WorkBook name which is to be graphed", "data");
if(wpName.IsEmpty()) // executed if user does not enter anything in the InputBox pop up window
{
printf("Try again.You enetered empty space.Operation Cancelled!\n");
return;
}
WorksheetPage wp(wpName);
// loop all worksheets in the workbook, add plots to graph
for(int iwks = 0; iwks <wp.Layers.Count();iwks++)
{
Worksheet wks = wp.Layers(iwks);
if(wks.IsValid())
{
GraphPage gp;
gp.Create("Origin"); // create graph page
string gpName,wksName; // used to name a graph page
wksName = wks.GetName(); // name of worksheet
gpName.Format("%s%s%s",wpName,"_",wksName.Right(3)); // this is name of the graph page
gp.SetName(gpName); // set graph page name
GraphLayer gl = gp.Layers(0); // get graph layer in graph page
if(gl)
{
DataRange dr;
dr.Add(wks,ic1-1, "X"); // X data range
dr.Add(wks,ic2-1, "Y"); // Y data range
//the internal Origin plot type id, see IDM_PLOT_* in oPlotIDs.h.
gl.AddPlot(dr, IDM_PLOT_SCATTER); // add scatter plot
gl.GroupPlots(0); // group all plots in the graph layer
gl.Rescale(ANL_NO_ROUNDING); // rescale graph layer
// Get the first data plot in the layer:
DataPlot dp = gl.DataPlots(0);
// Set the color to black and repaint:
dp.SetColor(0, TRUE);
Tree trFormat;
trFormat.Root.Symbol.Shape.nVal = 5; // set shape: diamond
trFormat.Root.Symbol.Interior.nVal = 1; // interior: empty
trFormat.Root.Symbol.Size.nVal = 12; // set size: 12
}
printf("Graph page: %i.\tName of Graph page: %s.\n",iwks+1 ,gp.GetName()); // name of graph page
}
}
}
AB |
|
a.abc.b35
175 Posts |
Posted - 05/17/2011 : 10:09:45 PM
|
One more info : Whatever number I change in the trFormat part, I always get the default black square (filled) with size 9 as the symbol on my graph. Please help.
AB |
 |
|
rlewis
Canada
253 Posts |
Posted - 05/18/2011 : 12:43:15 AM
|
Try modifyng your code to something like ...
Tree trFormat=gl.GetFormat(FPB_ALL,FOB_ALL,true, true);
trFormat.Root.Symbol.Shape.nVal = 5; // set shape: diamond
trFormat.Root.Symbol.Interior.nVal = 1; // interior: empty
trFormat.Root.Symbol.Size.nVal = 12; // set size: 12
gl.ApplyFormat(trFormat,true,true);
|
 |
|
Penn
China
644 Posts |
Posted - 05/18/2011 : 02:06:11 AM
|
Hi,
In your code, you have not apply the format to the plot yet. You need to use the UpdateThemeIDs and ApplyFormat methods to do that. So, you need to add more lines to do that, such as (pay attention to the red lines):
void GraphWorkBookXY(int ic1,int ic2)
{
// enter Workbook whose worksheets are to be graphed
string wpName = InputBox("Please enter the WorkBook name which is to be graphed", "data");
if(wpName.IsEmpty()) // executed if user does not enter anything in the InputBox pop up window
{
printf("Try again.You enetered empty space.Operation Cancelled!\n");
return;
}
WorksheetPage wp(wpName);
// loop all worksheets in the workbook, add plots to graph
for(int iwks = 0; iwks <wp.Layers.Count();iwks++)
{
Worksheet wks = wp.Layers(iwks);
if(wks.IsValid())
{
GraphPage gp;
gp.Create("Origin"); // create graph page
string gpName,wksName; // used to name a graph page
wksName = wks.GetName(); // name of worksheet
gpName.Format("%s%s%s",wpName,"_",wksName.Right(3)); // this is name of the graph page
gp.SetName(gpName); // set graph page name
GraphLayer gl = gp.Layers(0); // get graph layer in graph page
if(gl)
{
DataRange dr;
dr.Add(wks,ic1-1, "X"); // X data range
dr.Add(wks,ic2-1, "Y"); // Y data range
//the internal Origin plot type id, see IDM_PLOT_* in oPlotIDs.h.
gl.AddPlot(dr, IDM_PLOT_SCATTER); // add scatter plot
gl.GroupPlots(0); // group all plots in the graph layer
gl.Rescale(ANL_NO_ROUNDING); // rescale graph layer
// Get the first data plot in the layer:
DataPlot dp = gl.DataPlots(0);
// Set the color to black and repaint:
dp.SetColor(0, TRUE);
Tree trFormat;
trFormat.Root.Symbol.Shape.nVal = 5; // set shape: diamond
trFormat.Root.Symbol.Interior.nVal = 1; // interior: empty
trFormat.Root.Symbol.Size.nVal = 12; // set size: 12
//
if(0==dp.UpdateThemeIDs(trFormat.Root))
{
dp.ApplyFormat(trFormat, true, true);
}
}
printf("Graph page: %i.\tName of Graph page: %s.\n",iwks+1 ,gp.GetName()); // name of graph page
}
}
}
Penn |
 |
|
a.abc.b35
175 Posts |
Posted - 05/18/2011 : 1:03:02 PM
|
Thanks a lot Penn. It works !! ........... @ rlewis ; I tried your method also but it gives me errors ! I suppose it has something to do with the origin version I am using.
AB |
 |
|
a.abc.b35
175 Posts |
Posted - 05/22/2011 : 02:17:21 AM
|
I have one more question, I need to set the Y scale range from 0 to 1. How can I do it by the tree Node method above, for a series of graphs ?
AB |
 |
|
a.abc.b35
175 Posts |
Posted - 05/22/2011 : 02:25:06 AM
|
Also, how do I set the increments on Y and X scale and also the number of minor ticks on the scale ?
AB |
 |
|
Penn
China
644 Posts |
Posted - 05/22/2011 : 9:42:16 PM
|
Hi,
You can get the format tree of the axis, and then print it out to see the structure of the format tree. For more details, please refer to the serial of examples on axis format.
Penn |
 |
|
|
Topic  |
|
|
|