The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Adding two columns

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
arehman1289 Posted - 05/14/2014 : 1:02:24 PM
Hello,
I would like to know the sum function in origin C not Labtalk.
I have about 170 columns in worksheet 1. I would like to take the sum of each column and put it into worksheet 2.
Could you please guide me ?
Thanks
29   L A T E S T    R E P L I E S    (Newest First)
bobey Posted - 03/10/2015 : 12:17:52 AM
too mayny quote here, I can't read all the content @@
Castiel Posted - 10/24/2014 : 09:11:18 AM
quote:
Originally posted by arehman1289

Hello again ,

Thank you very much for your reply. So far its working quite as wanted. One thing, I want to rotate a label on the x-axis by 90 since its a bit long. Im using

tr.Root.Labels.BottomLabels.Format.Rotate.nVal = 90;

but doesnt work.

Please could you tell me how its done ?

Danke


The Rotate (deg.) in "Axis Dialog"->"Tick Labels"->"Bottom"->"Format" does not mean the TreeNode tr.Root.Labels.BottomLabels.Format.Rotate. Have a try of
t.Root.Labels.BottomLabels.Angle.dVal = 90.0;


©c¡Ï   ¤È¥¹  ©f¨u©c  ©c¥ì    ¥Î¤³  ©c/     ©¦£¯
 ©c¨Ê¥Î ¤´¥¨  ¥ó ¨×   ¥ó¤á' ¥Ì©¦¥­   /¤í  ¥Õ©¦©f
   ¨Ö             ¦á          ©¦£þ  ©` ¥Õ   ©¦
                              ©¦
arehman1289 Posted - 10/23/2014 : 11:07:02 AM
Hello again ,

Thank you very much for your reply. So far its working quite as wanted. One thing, I want to rotate a label on the x-axis by 90 since its a bit long. Im using

tr.Root.Labels.BottomLabels.Format.Rotate.nVal = 90;

but doesnt work.

Please could you tell me how its done ?

Danke
Castiel Posted - 10/14/2014 : 10:22:19 AM
quote:
Originally posted by arehman1289

Hello Castiel,

Thank you very much for your last message, It worked quite brilliantly and my work is much more organized now. I was now working on making the graphs simpler and better organized. I managed to fix most of it except a few minor details.Before this I have another basic question

when I import a file name REMODD1.ANA I face no problems but when I change it to REMODD_hour.ANAh the program doesnt import at all. Im using the simple if(0 == AscImpReadFileStruct(strFile, &ai) ), as in the manual. please help ?

1. I tried everything from the manual from section 6.1.8 to 6.1.12 but it didnt work for me. Firstly im trying to delete the minor ticks on the X-Axis and have only 8 major ticks. Im using this code but it doesnt make any difference:

// Graph 1: Plot the yearly values in TWh of heat producers and consumers //

DataRange dr;
dr.Add(wks3, 0, "X");
dr.Add(wks3, 1, "Y");
dr.Add(wks3, 2, "Y");
dr.Add(wks3, 3, "Y");
dr.Add(wks3, 4, "Y");
dr.Add(wks3, 5, "Y");
dr.Add(wks3, 6, "Y");
dr.Add(wks3, 7, "Y");


GraphPage gp;
gp.Create("column"); // Create graph with the specified template
GraphLayer gl = gp.Layers(-1); // Get active graph layer

GraphObject grXL = gl.GraphObjects("XB"); // Get X axis label
GraphObject grYL = gl.GraphObjects("YL"); // Get Y axis label

Axis axesX = gl.XAxis;

DataPlot dp = gl.DataPlots(0);
// Get all properties of the related objects of the colormap data plot
Tree tr;

// Set ticks color as Auto, depend on the color of data plot
tr.Root.Ticks.BottomTicks.Major.nVal = 8; // 0: In and Out
tr.Root.Ticks.BottomTicks.Minor.nVal = 0; // 2: Out
tr.Root.Labels.Size.nVal = 12;

gp.Rename("Heating techs");
grXL.Text = "Technologies";
grYL.Text = "Energy/TWh";

index = gl.AddPlot(dr, IDM_PLOT_COLUMN);
gl.Rescale();

2. The font of the labels on the x-axis are too big and I want to set them to 12 instead of 18. How can I do that by code.

3. The legend box to the right of the graph covers about half the page when it launches. I always have to manually make it smaller. Is there anyway to do this by code ?

Looking forward to your response.

Thanks
Abdur



Not sure if one can help much. The first answer to the very first question is here: http://stackoverflow.com/help/how-to-ask

I'm afraid you just defined a Tree tr and assigned some values to it and just threw it away. Therefore, of course, nothing changes. You need UpdateThemeIDs() and ApplyFormat().
Axis xAxis = gl.XAxis;
Tree tr;

/* 8 major ticks */
tr.Root.Scale.IncrementBy.nVal = 1;    // SET_MAJOR_TICKS_BY_COUNT;
tr.Root.Scale.Value.nVal = 8;    // Possibly not results in 8, dependens on you options setting. Don't know much about this....

/* 0 minor tick */
tr.Root.Scale.MinorTicksCount.nVal = 0;

/* font size: 12 */
tr.Root.Labels.BottomLabels.Font.Size.nVal = 12;

xAxis.UpdateThemeIDs(tr.Root);
xAxis.ApplyFormat(tr, TRUE, TRUE);


The Legend is a GraphObject, and there are DX, DY, Left, Top, Width, Height.... Just check the Origin C reference. For example,
GraphObject goLegend = gl.GraphObjects("Legend");
goLegend.Left = 0;
goLegend.Top = 0;



©c¡Ï   ¤È¥¹  ©f¨u©c  ©c¥ì    ¥Î¤³  ©c/     ©¦£¯
 ©c¨Ê¥Î ¤´¥¨  ¥ó ¨×   ¥ó¤á' ¥Ì©¦¥­   /¤í  ¥Õ©¦©f
   ¨Ö             ¦á          ©¦£þ  ©` ¥Õ   ©¦
                              ©¦
arehman1289 Posted - 10/13/2014 : 12:22:14 PM
Hello Castiel,

Thank you very much for your last message, It worked quite brilliantly and my work is much more organized now. I was now working on making the graphs simpler and better organized. I managed to fix most of it except a few minor details.Before this I have another basic question

when I import a file name REMODD1.ANA I face no problems but when I change it to REMODD_hour.ANAh the program doesnt import at all. Im using the simple if(0 == AscImpReadFileStruct(strFile, &ai) ), as in the manual. please help ?

1. I tried everything from the manual from section 6.1.8 to 6.1.12 but it didnt work for me. Firstly im trying to delete the minor ticks on the X-Axis and have only 8 major ticks. Im using this code but it doesnt make any difference:

// Graph 1: Plot the yearly values in TWh of heat producers and consumers //

DataRange dr;
dr.Add(wks3, 0, "X");
dr.Add(wks3, 1, "Y");
dr.Add(wks3, 2, "Y");
dr.Add(wks3, 3, "Y");
dr.Add(wks3, 4, "Y");
dr.Add(wks3, 5, "Y");
dr.Add(wks3, 6, "Y");
dr.Add(wks3, 7, "Y");


GraphPage gp;
gp.Create("column"); // Create graph with the specified template
GraphLayer gl = gp.Layers(-1); // Get active graph layer

GraphObject grXL = gl.GraphObjects("XB"); // Get X axis label
GraphObject grYL = gl.GraphObjects("YL"); // Get Y axis label

Axis axesX = gl.XAxis;

DataPlot dp = gl.DataPlots(0);
// Get all properties of the related objects of the colormap data plot
Tree tr;

// Set ticks color as Auto, depend on the color of data plot
tr.Root.Ticks.BottomTicks.Major.nVal = 8; // 0: In and Out
tr.Root.Ticks.BottomTicks.Minor.nVal = 0; // 2: Out
tr.Root.Labels.Size.nVal = 12;

gp.Rename("Heating techs");
grXL.Text = "Technologies";
grYL.Text = "Energy/TWh";

index = gl.AddPlot(dr, IDM_PLOT_COLUMN);
gl.Rescale();

2. The font of the labels on the x-axis are too big and I want to set them to 12 instead of 18. How can I do that by code.

3. The legend box to the right of the graph covers about half the page when it launches. I always have to manually make it smaller. Is there anyway to do this by code ?

Looking forward to your response.

Thanks
Abdur
Castiel Posted - 10/06/2014 : 12:00:36 PM
quote:
Originally posted by arehman1289

Hello Castiel,

I am making a subfolder in the root folder and then activate that folder, but when I create a workbook it automatically creates another subfolder named folder1 and the workbook is inserted into it. This is my code.

void import()
{

//**********************************************************************************/
// Import the REMODD.ANA file and have the sum of the 8760 hourly values of the column written at the last row //

//Creating the subfolder
Folder fld = Project.RootFolder;
Folder subfld = fld.AddSubfolder("tester");
subfld.Activate();


// Importing the source file
WorksheetPage wksPage = Project.WorksheetPages(0);

ASCIMP ai;

string strFile = "D:\\REMODD1.ANA";

if(0 == AscImpReadFileStruct(strFile, &ai) ) // detect if the file's format is correct

{
wks0 = wksPage.Layers(0);
if(0 == wks0.ImportASCII(strFile, ai))
out_str("REMODD1.ANA imported successful.");
}



wks0.SetName("REMODD1");


strFile = "D:\\REMODD2.ANA";
index = wksPage.AddLayer("REMODD2");

if(0 == AscImpReadFileStruct(strFile, &ai) ) // detect if the file's format is correct


{
wks = wksPage.Layers(1);
if(0 == wks.ImportASCII(strFile, ai))
out_str("REMODD2.ANA imported successful.");
}


// Labelling the worksheet and getting the number of rows and columns

nRows = wks.GetNumRows();
nCols = wks.GetNumCols();

//Summing up the values of each column and placing it in the 8760'th cell of the column
j = 0;
foreach(Column cc in wks.Columns)
{
wks.Columns(j).SetWidth(8);
vectorbase &dsCol = cc.GetDataObject();
vector vec2;
dsCol.GetSubVector(vec2, 0, 8759);
double vv;
vec2.Sum(vv);
vv = vv/1000;
wks.SetCell(8760,j, vv);
j = j+1;
}

}

I dont know why this happens, although you said i simply need to activate the folder to insert the workbook in it.

I think somehow the class worksheet automatically creates a new folder. I tried reading the reason in the manual but couldnt find anything.

please help.

Thanks



By default, when you create a new project, there's a Workbook named "Book1" in \UNTITLED\Folder1. (UNTITLED should be the project name if it's been saved before.) I'm afraid your code does not create a workbook. Here,
"WorksheetPage wksPage = Project.WorksheetPages(0);
wksPage is Book1, and it's in \UNTITLED\Folder1. To create a workboook,

WorksheetPage wp;
wp.Create();


©c¡Ï   ¤È¥¹  ©f¨u©c  ©c¥ì    ¥Î¤³  ©c/     ©¦£¯
 ©c¨Ê¥Î ¤´¥¨  ¥ó ¨×   ¥ó¤á' ¥Ì©¦¥­   /¤í  ¥Õ©¦©f
   ¨Ö             ¦á          ©¦£þ  ©` ¥Õ   ©¦
                              ©¦
arehman1289 Posted - 10/06/2014 : 11:00:55 AM
Hello Castiel,

I am making a subfolder in the root folder and then activate that folder, but when I create a workbook it automatically creates another subfolder named folder1 and the workbook is inserted into it. This is my code.

void import()
{

//**********************************************************************************/
// Import the REMODD.ANA file and have the sum of the 8760 hourly values of the column written at the last row //

//Creating the subfolder
Folder fld = Project.RootFolder;
Folder subfld = fld.AddSubfolder("tester");
subfld.Activate();


// Importing the source file
WorksheetPage wksPage = Project.WorksheetPages(0);

ASCIMP ai;

string strFile = "D:\\REMODD1.ANA";

if(0 == AscImpReadFileStruct(strFile, &ai) ) // detect if the file's format is correct

{
wks0 = wksPage.Layers(0);
if(0 == wks0.ImportASCII(strFile, ai))
out_str("REMODD1.ANA imported successful.");
}



wks0.SetName("REMODD1");


strFile = "D:\\REMODD2.ANA";
index = wksPage.AddLayer("REMODD2");

if(0 == AscImpReadFileStruct(strFile, &ai) ) // detect if the file's format is correct


{
wks = wksPage.Layers(1);
if(0 == wks.ImportASCII(strFile, ai))
out_str("REMODD2.ANA imported successful.");
}


// Labelling the worksheet and getting the number of rows and columns

nRows = wks.GetNumRows();
nCols = wks.GetNumCols();

//Summing up the values of each column and placing it in the 8760'th cell of the column
j = 0;
foreach(Column cc in wks.Columns)
{
wks.Columns(j).SetWidth(8);
vectorbase &dsCol = cc.GetDataObject();
vector vec2;
dsCol.GetSubVector(vec2, 0, 8759);
double vv;
vec2.Sum(vv);
vv = vv/1000;
wks.SetCell(8760,j, vv);
j = j+1;
}

}

I dont know why this happens, although you said i simply need to activate the folder to insert the workbook in it.

I think somehow the class worksheet automatically creates a new folder. I tried reading the reason in the manual but couldnt find anything.

please help.

Thanks
Castiel Posted - 10/01/2014 : 05:06:51 AM
quote:
Originally posted by arehman1289

Hello,

Once again I have a few short questions, but hopefully this might be the last time.

1. When I am extracting a value from a cell using e.g wks.Cell(8760,1) can I use the long-name instead of the column numbers to make it easier to debug ? Is there any other way of doing this ?

2. Is it possible to create a folder in the project window and then place workbooks and graphs in it, instead of creating all the workbooks and graphs and then moving them into folders ?
Also when workbooks are in different folders can the individual cells of a workbook in a different folder be called in the same fashion using e.g wks.Cell(8760,1).

Thank you very much for your past help and looking forward to your answer.

Thanks



1. No, but you can first find the column by long name and then get its index. See Datasheet::FindCol() and OriginObject::GetIndex(). The column may be invalid then the index = -1. And, there may be more than one column shares one long name.
2.1 Workbooks and Graphs are created in the active folder. You can make a folder active by Folder::Activate().
2.2 As long as wks is valid, you can use wks.Cell() wherever it is.

©c¡Ï   ¤È¥¹  ©f¨u©c  ©c¥ì    ¥Î¤³  ©c/     ©¦£¯
 ©c¨Ê¥Î ¤´¥¨  ¥ó ¨×   ¥ó¤á' ¥Ì©¦¥­   /¤í  ¥Õ©¦©f
   ¨Ö             ¦á          ©¦£þ  ©` ¥Õ   ©¦
                              ©¦
arehman1289 Posted - 09/30/2014 : 10:51:07 AM
Hello,

Once again I have a few short questions, but hopefully this might be the last time.

1. When I am extracting a value from a cell using e.g wks.Cell(8760,1) can I use the long-name instead of the column numbers to make it easier to debug ? Is there any other way of doing this ?

2. Is it possible to create a folder in the project window and then place workbooks and graphs in it, instead of creating all the workbooks and graphs and then moving them into folders ?
Also when workbooks are in different folders can the individual cells of a workbook in a different folder be called in the same fashion using e.g wks.Cell(8760,1).

Thank you very much for your past help and looking forward to your answer.

Thanks
Castiel Posted - 09/16/2014 : 09:59:17 AM
quote:
Originally posted by arehman1289

Hello Castiel,

Thank you so much for your previous replies. After a few weeks I am working on expanding my origin C code, but right at the start I am facing an error.

I am trying to import two files and extract data and analyze it. But the problem is after I import the first file, the second is not imported giving the error when i call the function (it compiles).

D:\Users\amazhar\Documents\OriginLab\91\Anwenderdateien\OriginC\energybalance_v2.c(62) :Origin C Function Runtime Error, failed to find object during method call

The code looks somewhat like this

WorksheetPage wksPage("D:\\REMODD.ANA");

ASCIMP ai;

string strFile = "D:\\REMODD_year.ANA";

if(0 == AscImpReadFileStruct(strFile, &ai) ) // detect if the file's format is correct

{
wks0 = Project.ActiveLayer();
if(0 == wks0.ImportASCII(strFile, ai))
out_str("REMOD_year.ANA imported successful.");
}



wks0.SetName(strFile);
strFile = "D:\\REMODD.ANAh";
index = wksPage.AddLayer("REMODD.ANA");

if(0 == AscImpReadFileStruct(strFile, &ai) ) // detect if the file's format is correct

{
wks = wksPage.Layers(1);
if(0 == wks.ImportASCII(strFile, ai))
out_str("REMOD.ANA imported successful.");
}

Please help me importing two files on separate worksheets.

Thank you



I'm afraid the wksPage is invalid, then wksPage.AddLayer("REMODD.ANA") fails. You can check this by the return value of wksPage.IsValid() or simply if(!wksPage){/* */}.
Here, WorksheetPage wksPage("D:\\REMODD.ANA"), usually "D:\REMODD.ANA" is not a valid (short) name.
WorksheetPage( LPCTSTR lpcszName ) // lpcszName [input]The name of an existing Origin worksheet page.

Make sure you know the difference between a long name and a short name:
http://www.originlab.com/doc/User-Guide/Worksheets-Columns#Naming_Workbooks.2C_Worksheets_and_Columns

This is another topic. You should have created a new one.


©c¡Ï   ¤È¥¹  ©f¨u©c  ©c¥ì    ¥Î¤³  ©c/     ©¦£¯
 ©c¨Ê¥Î ¤´¥¨  ¥ó ¨×   ¥ó¤á' ¥Ì©¦¥­   /¤í  ¥Õ©¦©f
   ¨Ö             ¦á          ©¦£þ  ©` ¥Õ   ©¦
                              ©¦
arehman1289 Posted - 09/16/2014 : 04:18:59 AM
Hello Castiel,

Thank you so much for your previous replies. After a few weeks I am working on expanding my origin C code, but right at the start I am facing an error.

I am trying to import two files and extract data and analyze it. But the problem is after I import the first file, the second is not imported giving the error when i call the function (it compiles).

D:\Users\amazhar\Documents\OriginLab\91\Anwenderdateien\OriginC\energybalance_v2.c(62) :Origin C Function Runtime Error, failed to find object during method call

The code looks somewhat like this

WorksheetPage wksPage("D:\\REMODD.ANA");

ASCIMP ai;

string strFile = "D:\\REMODD_year.ANA";

if(0 == AscImpReadFileStruct(strFile, &ai) ) // detect if the file's format is correct

{
wks0 = Project.ActiveLayer();
if(0 == wks0.ImportASCII(strFile, ai))
out_str("REMOD_year.ANA imported successful.");
}



wks0.SetName(strFile);
strFile = "D:\\REMODD.ANAh";
index = wksPage.AddLayer("REMODD.ANA");

if(0 == AscImpReadFileStruct(strFile, &ai) ) // detect if the file's format is correct

{
wks = wksPage.Layers(1);
if(0 == wks.ImportASCII(strFile, ai))
out_str("REMOD.ANA imported successful.");
}

Please help me importing two files on separate worksheets.

Thank you
Castiel Posted - 07/04/2014 : 11:29:49 AM
quote:
Originally posted by arehman1289

Hello Castiel,

I tried creating the executable button but it still doesn't work. I have to manually add the code to the users folder in each computer and link it. The output still doesnt take into consideration the graph templates and is not explained in the manual either.

Is there any way I could call you by phone or send you the code along with the templates ?

Anxiously waiting for your help.

Thanks



Where are your templates? Did you add the templates as Additional files? By default, they should be in User Files Folder.

I think it would be better if you can call for technical support: http://www.originlab.com/index.aspx?go=SUPPORT

©c¡Ï   ¤È¥¹  ©f¨u©c  ©c¥ì    ¥Î¤³  ©c/     ©¦£¯
 ©c¨Ê¥Î ¤´¥¨  ¥ó ¨×   ¥ó¤á' ¥Ì©¦¥­   /¤í  ¥Õ©¦©f
   ¨Ö             ¦á          ©¦£þ  ©` ¥Õ   ©¦
                              ©¦
arehman1289 Posted - 07/01/2014 : 04:48:10 AM
Hello Castiel,

I tried creating the executable button but it still doesn't work. I have to manually add the code to the users folder in each computer and link it. The output still doesnt take into consideration the graph templates and is not explained in the manual either.

Is there any way I could call you by phone or send you the code along with the templates ?

Anxiously waiting for your help.

Thanks
Castiel Posted - 06/26/2014 : 11:11:37 AM
quote:
Originally posted by arehman1289

Thank you so much once again Castiel.

One final question

A colleague of mine wants to analyze various sets of data on his computer using the code I have written in Origin C. Based on the manual I see that he has to add the file in his users folder, compile it and before that put the graphical templates .otp into the users folder.

Is there a simpler way since he is not much familiar with origin C ? Can I make a simple .exe file combined with the .c and .otp files ??

Thanks



Which part of the manual have you read? The following one should be clear enough:
http://www.originlab.com/doc/OriginC/guide/Distributing-Origin-C-Code
in your case, just add the templates, as well as your c files, as Additional files.

©c¡Ï   ¤È¥¹  ©f¨u©c  ©c¥ì    ¥Î¤³  ©c/     ©¦£¯
 ©c¨Ê¥Î ¤´¥¨  ¥ó ¨×   ¥ó¤á' ¥Ì©¦¥­   /¤í  ¥Õ©¦©f
   ¨Ö             ¦á          ©¦£þ  ©` ¥Õ   ©¦
                              ©¦
arehman1289 Posted - 06/26/2014 : 09:47:00 AM
Thank you so much once again Castiel.

One final question

A colleague of mine wants to analyze various sets of data on his computer using the code I have written in Origin C. Based on the manual I see that he has to add the file in his users folder, compile it and before that put the graphical templates .otp into the users folder.

Is there a simpler way since he is not much familiar with origin C ? Can I make a simple .exe file combined with the .c and .otp files ??

Thanks
Castiel Posted - 06/25/2014 : 11:43:32 AM
quote:
Originally posted by arehman1289

Do you mean to say I can make a template based on a worksheet with the rows together and then use that template for this original worksheet using origin C ?



Here would be my solution:
1. Add an extra column to unstack your data: for example, in Col(D), Row 4,8,12,16 share the group number "4". You can generate col(D) by Origin C or LabTalk or even manually....


2. Now unstack the columns, see the menu Worksheet->Unstack Columns. You may want to set the recalculate mode to be Auto. (See, rows re-arranged...)


3. Then use the graph template for graphing.
For example:
void createFromOTP(int iX, int iY)
{
    GraphPage gp;
    gp.Create("UserDefinedColumn1.otp");
    GraphLayer gl = gp.Layers();
    Worksheet wks("[Book1]UnstackCols1");
    DataRange dr;
    dr.Add(wks, iX, "X", iX);
    dr.Add(wks, iY, "Y", iY);
    gl.AddPlot(dr, IDM_PLOT_COLUMN);
    gl.Rescale();
}

Call the function to plot graphs in LabTalk: for(i=0;i<=9;i+=3){createFromOTP(i,i+1);}



You can unstack columns with your own Origin C function as well....But why not just use the one already available?

©c¡Ï   ¤È¥¹  ©f¨u©c  ©c¥ì    ¥Î¤³  ©c/     ©¦£¯
 ©c¨Ê¥Î ¤´¥¨  ¥ó ¨×   ¥ó¤á' ¥Ì©¦¥­   /¤í  ¥Õ©¦©f
   ¨Ö             ¦á          ©¦£þ  ©` ¥Õ   ©¦
                              ©¦
arehman1289 Posted - 06/24/2014 : 11:15:57 AM
Do you mean to say I can make a template based on a worksheet with the rows together and then use that template for this original worksheet using origin C ?
Castiel Posted - 06/24/2014 : 10:09:09 AM
quote:
Originally posted by arehman1289

Thank you Castiel.

Your advice always works perfectly. It seems you really have origin C on your finger tips. Thank you so much.

As you said I am making templates and then using them via origin C. I have this data set but I am unable to make the template as wanted.

1. I need to plot every 4th value in the table...i.e row 20..24..28..32 and so on. when i use it in the template the rows in the middle i.e 21,22,23 etc also get plotted with zero values. Is there any way I can skip these when making this custom bar chart template.

2. I wish to plot single values in stead of data ranges. Last time you told me to plot in between rows this is used

DataRange dr;
dr.Add(wks, 0, "X", 0, 5, 10);
dr.Add(wks, 1, "Y", 1, 5, 10);

but is it possible to plot only the value in row 4, then row 8 etc.

Looking forward to your reply.

Thanks




I think you just found some shortcomings of it....Why not creating another worksheet with data for graphing staying together? It should be easy enough to re-arrange these data in Origin C.

©c¡Ï   ¤È¥¹  ©f¨u©c  ©c¥ì    ¥Î¤³  ©c/     ©¦£¯
 ©c¨Ê¥Î ¤´¥¨  ¥ó ¨×   ¥ó¤á' ¥Ì©¦¥­   /¤í  ¥Õ©¦©f
   ¨Ö             ¦á          ©¦£þ  ©` ¥Õ   ©¦
                              ©¦
arehman1289 Posted - 06/24/2014 : 04:18:15 AM
eagerly waiting for your answer plz
arehman1289 Posted - 06/20/2014 : 12:00:56 PM
Thank you Castiel.

Your advice always works perfectly. It seems you really have origin C on your finger tips. Thank you so much.

As you said I am making templates and then using them via origin C. I have this data set but I am unable to make the template as wanted.

1. I need to plot every 4th value in the table...i.e row 20..24..28..32 and so on. when i use it in the template the rows in the middle i.e 21,22,23 etc also get plotted with zero values. Is there any way I can skip these when making this custom bar chart template.

2. I wish to plot single values in stead of data ranges. Last time you told me to plot in between rows this is used

DataRange dr;
dr.Add(wks, 0, "X", 0, 5, 10);
dr.Add(wks, 1, "Y", 1, 5, 10);

but is it possible to plot only the value in row 4, then row 8 etc.

Looking forward to your reply.

Thanks
Castiel Posted - 06/17/2014 : 12:17:54 PM
quote:
Originally posted by arehman1289

Hello Castiel,

Thank you very much, once again for your reply.

1. Yes I mistakenly wrote bar chart instead of column chart. I have the set of rows and data as shown and the plot in excel., that i would like to make on origin C. please help.

2. I would like to create another column chart displaying only two columns for each technology. Is it possible to plot the addition of row 6 and 7 with row 8 for each technology.

Looking forward to your reply.

Thanks





1. You may need to transpose the data in Origin:


2. Create a graph manually and save it as template, say, "ColumnExcelStyle.otp":


3. Create graph with the template and add DataPlot to it:
void createFromOTP()
{
	GraphPage gp;
	gp.Create("ColumnExcelStyle.otp");
	GraphLayer gl = gp.Layers();
	Worksheet wks("[Book1]Sheet1");
	if( wks )
		gl.AddPlot(wks);
	
	return;
}


4. Re-arrange/re-calculate your data and save into another worksheet, again, use the template to plot another graph.


To create a graph with Origin C only is a lot of work. Make good use of template!

©c¡Ï   ¤È¥¹  ©f¨u©c  ©c¥ì    ¥Î¤³  ©c/     ©¦£¯
 ©c¨Ê¥Î ¤´¥¨  ¥ó ¨×   ¥ó¤á' ¥Ì©¦¥­   /¤í  ¥Õ©¦©f
   ¨Ö             ¦á          ©¦£þ  ©` ¥Õ   ©¦
                              ©¦
arehman1289 Posted - 06/16/2014 : 11:05:29 AM
looking forward to ur answer plz
arehman1289 Posted - 06/12/2014 : 06:12:23 AM
Hello Castiel,

Thank you very much, once again for your reply.

1. Yes I mistakenly wrote bar chart instead of column chart. I have the set of rows and data as shown and the plot in excel., that i would like to make on origin C. please help.

2. I would like to create another column chart displaying only two columns for each technology. Is it possible to plot the addition of row 6 and 7 with row 8 for each technology.

Looking forward to your reply.

Thanks

Castiel Posted - 06/05/2014 : 10:45:03 AM
quote:
Originally posted by arehman1289

Thank you very much Castiel. I did as you said and the code works fine now. Thanks a lot.
I am now in the process of plotting the data and get stuck at several points whose answers I couldn't find even in the manual.

1. Is it possible to plot a bar chart or a scatter plot with specific values in a column and not the entire column ?

2. I need to plot a bar chart with values on the x axis and label each bar specifically. I tried several ways but the reverse happens. Here is how I do it.

DataRange dr;
dr.Add(wks3, 1, "X"); // Construct data range with one column

GraphPage gp;
gp.Create("BAR"); // Create graph with the specified template
GraphLayer gl = gp.Layers(-1); // Get active graph layer

int index4 = gl.AddPlot(dr, IDM_PLOT_BAR);
gl.Rescale();

3. How can I change the color of the bars and display the value in the bars like excel.

Please help or refer me to a relevant manual.

Thanks



1. As far as I know, you can create more than one DataRange for non-consecutive points. Say, There are 100 rows in Col(0) and Col(1). To plot with data from Row 5 to Row 10, and with data from Row 15 to Row 20, the DataRange is:
DataRange dr;
dr.Add(wks, 0, "X", 0, 5, 10);
dr.Add(wks, 1, "Y", 1, 5, 10);

dr.Add(wks, 0, "X", 0, 15, 20);
dr.Add(wks, 0, "Y", 0, 15, 20);
gl.AddPlot(dr);


2. What do mean by "a bar with values on the x axis and label each bar specifically"? Can you just plot it manually and take a screenshot? Maybe you need to plot a "Column" instead of "Bar"?

3. The color of a bar plot, well, is actually the fill color, which cannot be set by DataPlot::SetColor(). Here it is:
Tree t;
t = dp.GetFormat(FPB_ALL, FOB_ALL, TRUE, TRUE);
t.Root.Pattern.Fill.FillColor.nVal = 2; // Green. Or 0x010080f0 - Red = 0xf0, Green = 0x80, Blue = 0x00.
dp.UpdateThemeIDs(t.Root);
dp.ApplyFormat(t, TRUE, TRUE);


How does it look like in Excel? Another screenshot?

©c¡Ï   ¤È¥¹  ©f¨u©c  ©c¥ì    ¥Î¤³  ©c/     ©¦£¯
 ©c¨Ê¥Î ¤´¥¨  ¥ó ¨×   ¥ó¤á' ¥Ì©¦¥­   /¤í  ¥Õ©¦©f
   ¨Ö             ¦á          ©¦£þ  ©` ¥Õ   ©¦
                              ©¦
arehman1289 Posted - 06/04/2014 : 10:37:24 AM
Thank you very much Castiel. I did as you said and the code works fine now. Thanks a lot.
I am now in the process of plotting the data and get stuck at several points whose answers I couldn't find even in the manual.

1. Is it possible to plot a bar chart or a scatter plot with specific values in a column and not the entire column ?

2. I need to plot a bar chart with values on the x axis and label each bar specifically. I tried several ways but the reverse happens. Here is how I do it.

DataRange dr;
dr.Add(wks3, 1, "X"); // Construct data range with one column

GraphPage gp;
gp.Create("BAR"); // Create graph with the specified template
GraphLayer gl = gp.Layers(-1); // Get active graph layer

int index4 = gl.AddPlot(dr, IDM_PLOT_BAR);
gl.Rescale();

3. How can I change the color of the bars and display the value in the bars like excel.

Please help or refer me to a relevant manual.

Thanks
Castiel Posted - 05/26/2014 : 09:03:32 AM
quote:
Originally posted by arehman1289

Hello,
thank you so much for the reply.
i found another way by simply adding the required length of the column in the last cell of this column.

for( int j =1; j < nCols-24 ; j++ )
{
Dataset dsCol(wks,j);
dsCol.SetLowerBound(0);
dsCol.SetUpperBound(8760);
Data_sum(&dsCol, &stat);
wks.SetCell(8760,j, stat.total/1000);
}

But the problem I face now is that i have a one cell break after 8760 rows of a column and more values below that. When i use dataset the cells below the 8760th row dissappear. i need them for a furthur calculation but now i dont have them any more.
please help.

thanks



You used SetLowerBound() and SetUpperBound(), which would delete data not in [0, 8760]. Use vector instead. You may need these two function: Column::GetDataObject() and vectorbase::GetSubVector().

©c¡Ï   ¤È¥¹  ©f¨u©c  ©c¥ì    ¥Î¤³  ©c/     ©¦£¯
 ©c¨Ê¥Î ¤´¥¨  ¥ó ¨×   ¥ó¤á' ¥Ì©¦¥­   /¤í  ¥Õ©¦©f
   ¨Ö             ¦á          ©¦£þ  ©` ¥Õ   ©¦
                              ©¦
arehman1289 Posted - 05/26/2014 : 08:47:55 AM
please help !!!
arehman1289 Posted - 05/21/2014 : 11:50:33 AM
Hello,
thank you so much for the reply.
i found another way by simply adding the required length of the column in the last cell of this column.

for( int j =1; j < nCols-24 ; j++ )
{
Dataset dsCol(wks,j);
dsCol.SetLowerBound(0);
dsCol.SetUpperBound(8760);
Data_sum(&dsCol, &stat);
wks.SetCell(8760,j, stat.total/1000);
}

But the problem I face now is that i have a one cell break after 8760 rows of a column and more values below that. When i use dataset the cells below the 8760th row dissappear. i need them for a furthur calculation but now i dont have them any more.
please help.

thanks
Castiel Posted - 05/15/2014 : 11:36:54 AM
quote:
Originally posted by arehman1289

Hello,
I would like to know the sum function in origin C not Labtalk.
I have about 170 columns in worksheet 1. I would like to take the sum of each column and put it into worksheet 2.
Could you please guide me ?
Thanks


Say, the worksheet 1 is [Book1]Sheet1, and worksheet 2 [Book1]Sheet2.


BOOL GetColSum()
{
    Worksheet wks1("[Book1]Sheet1");
    Worksheet wks2("[Book1]Sheet2");
    
    if( !wks1 || !wks2 )
        return FALSE;
    
    int cindex = wks2.AddCol();
    if( cindex == -1 )
        return FALSE;
    
    vector<double> vSum;
    foreach(Column cc in wks1.Columns)
    {
        vectorbase & vb = cc.GetDataObject();
        double dSum;
        vb.Sum(dSum);
        vSum.Add( dSum );
    }
    
    vectorbase & vbSum = wks2.Columns(cindex).GetDataObject();
    vbSum = vSum;
    
    return TRUE;
}


©c¡Ï   ¤È¥¹  ©f¨u©c  ©c¥ì    ¥Î¤³  ©c/     ©¦£¯
 ©c¨Ê¥Î ¤´¥¨  ¥ó ¨×   ¥ó¤á' ¥Ì©¦¥­   /¤í  ¥Õ©¦©f
   ¨Ö             ¦á          ©¦£þ  ©` ¥Õ   ©¦
                              ©¦

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000