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
 Simple Graphs problem.

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
hschausb Posted - 01/19/2021 : 1:30:35 PM
Origin Ver. and Service Release (Select Help-->About Origin): 2020b
Operating System: Win10

Hello fellow programmers.
I am turning to you today with a little bit of shame in my writing. I am having trouble setting up a simple graph. And I cannot find a working solution wit the Origin C programming guid. This is due to it doing an incredible job in explaining nothing and my inability to understand classes. So, I am asking you right now, please help me out here on the following questions.

I am starting with generating an existing worksheet and writing calculations in the cells of the worksheet. No problem there. Now I want to visualize the calculated values in a 2D graph in origins.
And here is the first problem. I have two options here. Only working with an existing graph and overwriting its content every time my program is started. Or, deleting the graph each time before initialization and then generating a new one. Both have pros and cons for me (mainly due to the lacking knowledge how to best program it).

First question would be. How do I check if a graph is already existing? I want to initialize my graph like this, if “Graph1” already exists.
GraphPage gp = Project.GraphPages(“Graph1”);
GraphLayer plot = gp.Layers(-1);

If not, a new one should be create.
GraphPage gp;
gp.Create("Origin", CREATE_HIDDEN);
GraphLayer plot = gp.Layers(-1);


Second question would be, if I am adding a new data set to the graph, how do I add multiple sets of Y values onto the same x value? I am assuming something like this:
DataRange dr;
dr.Add(wks, rowStart, colStart, rowEnd, colEnd);
plot.AddPlot(dr, xxxx);

Please be aware that these functions similar to the ones found in the origin guid. And yes these are/should be the command to properly use graphs. But I am assuming I am not properly using them. Because I cannot get a graph to work.

Lastly, I want to know if it is possible to clear a GraphLayer of its content like it is possible to clear a Worksheet of its content with:
wks.ClearData();
. With this I would not need to delete and then create a new graph each time my program is started. I could just use the existing “Graph1”

I already looked through a lot. And I really mean “A LOT” of origin c guids, handbooks and stuff. And I could not figure out how most of these things work. The origin c guid does such a bad job at explaining these things to new programmers. And its also pretty frustrating that class methods are explained in one or less examples without any commentary and output. I spent hours copying code from the guid, adding it in a test program, trying to understand the code step by step, only to find out it is not the right method/class/command for me.
7   L A T E S T    R E P L I E S    (Newest First)
YimingChen Posted - 01/25/2021 : 10:56:03 AM
You then will need to run Labtalk script in OC, try the code below:
LT_execute("legend.TEXT$= \l(1) aa%(CRLF)\l(2) bb%(CRLF)\l(3) cc");


James
hschausb Posted - 01/21/2021 : 5:11:15 PM
Thank you very much James. You really helped my out here alot.
I am really greatfull to you that you took your time and went through everything with me.
Really. Thank you very very much.



I still encountered a problem. Is there another methode to set the name of a plot line except vie the Long Name?
I am creating 2 different plot line per column. And each would have a different name.
YimingChen Posted - 01/21/2021 : 11:42:57 AM
The legend entry is picked up from column longname, so before plotting, you can use the code below as an example to set coloumn longname.
wks.Columns(0).SetLongName("Voltage of X");


Defining Dataplot dp1 at the beginning will cause trouble because your code then removes the data plot from the layer and dp1 becomes invalid.

Yiming
hschausb Posted - 01/21/2021 : 07:25:33 AM
quote:

How do you want to change the data range name? The data range should have the standard Origin range format like Y: [Book1]Sheet1!B"bb"[0:0] which specifies the column you picked.



I want to change the name of a range. In your example in "Book1", "Sheet1" with the range "0:0" is added. This is in line "B". By default upon adding this data range into a graph it displays this data set as "B". I want to know how I can change the displayed name "B" into something else like "Voltage of X". I assume the term "bb" in your example is exactly what I am looking for. How do I include this?

I am very sorry for my last question there. It was late and I definitely did not specify enough what I meant with “change colour”. Fortunately, you sent me the right solution. Thank you. I totally looked over this in the guid.

Everything works fine now. Thank you.
But out of curiosity. I do have a …. Formatting problem? Lets call it that. My code looks like this:

	WorksheetPage worksheet = Project.WorksheetPages("Book1");
	Worksheet wks = worksheet.Layers(0);
	GraphPage dataPlot_TerminatingGroup = Project.GraphPages("Graph1");	//Initializes graph 1
	GraphPage dataPlot_RU = Project.GraphPages("Graph2");		//Initializes graph 2
	GraphLayer plotTG = dataPlot_TerminatingGroup.Layers();		//Sets excessable layer onto graph 1
	GraphLayer plotRU = dataPlot_RU.Layers();			//Sets excessable layer onto graph 2

	DataRange drTG;			        //Datagrange of plotted data
	DataRange drRU;
	
	int nPlots;				//Number of plots in one graph
	unsigned char i;			//counter
	unsigned char row;
	unsigned char xyStart;			//Start and end point of the data range for the graph
	unsigned char xyEnd;
	
	
	//Removes all plots inside a graph window of "Terminating Groupds"
	nPlots = 0;
	nPlots = plotTG.DataPlots.Count(); 
        for(i = 0; i < nPlots; i++)
        plotTG.RemovePlot(0);
    
       //Removes all plots inside a graph window "Repeating Units"
       nPlots = 0;
       nPlots = plotRU.DataPlots.Count();    
       for(i = 0; i < nPlots; i++)
        plotRU.RemovePlot(0);
	
	//Gets range of data for TG graph
	xyStart = 1;
	row = 1;		//Start at first vlaues. (0 = headline)
	while(NANUM != wks.Cell(row, 0))
		row ++;
	row = row -1;		//-1 for last line is the "total" and does not count towards the data set.
	xyEnd = row;	        //Sets end of data range 
   
	//Adds start and end points of the data into the Data Set
	drTG.Add("X", wks, xyStart, 0, xyEnd, 0);		//Sets Data range of X-Achses into the Data Set
	drTG.Add("Y", wks, xyStart, 1, xyEnd, 1);		//Sets Data range of Y-Achsess into the Data Set
	drTG.Add("Y", wks, xyStart, 2, xyEnd, 2);
	drTG.Add("Y", wks, xyStart, 3, xyEnd, 3);
	drTG.Add("Y", wks, xyStart, 4, xyEnd, 4);
	
	//Sets the Data Range into the graph
	plotTG.AddPlot(drTG, IDM_PLOT_LINESYMB);
	plotTG.Rescale();
	
	
	//Gets the range of data for RU graph
	row = row + 2;
	while(NANUM == wks.Cell(row, 0))
		row++;
	xyStart = row;
	while(NANUM != wks.Cell(row, 0))
		row++;
	row = row-1;
	xyEnd = row;
	
	//Adds start and end points of the data into the Data Set
	drRU.Add("X", wks, xyStart, 0, xyEnd, 0);		//Sets Data range of X-Achses into the Data Set
	drRU.Add("Y", wks, xyStart, 1, xyEnd, 1);		//Sets Data range of Y-Achsess into the Data Set
	drRU.Add("Y", wks, xyStart, 2, xyEnd, 2);
	drRU.Add("Y", wks, xyStart, 3, xyEnd, 3);
	drRU.Add("Y", wks, xyStart, 4, xyEnd, 4);
	
	//Sets the Data Range into the graph
	plotRU.AddPlot(drRU, IDM_PLOT_LINESYMB);
	plotRU.Rescale();
	
	//Sets the colour of the plot lines
	DataPlot dp1 = plotTG.DataPlots(0);			//Initiates the data plot of the graph
	DataPlot dp2 = plotRU.DataPlots(0);
	bool bRepaint = true;					//Bool to enable repainting of the plot lines
	
	dp1.SetColor(SYSCOLOR_BLACK, bRepaint);
	dp2.SetColor(SYSCOLOR_ROYAL, bRepaint);


If I am writing your solution at the end of the program, the sys-colour is assigned correctly to the DataPlots. Every time this program is executed, the colours are the same.
But if I am initializing the “Dataplot dp1”and “bool bRepaint” at the top of the programm, and change the colour at the end of the program via “SetColor”, then thr colour changes randomly every run through. If I do it like this, it is like as I did not include your solution at all.
What is causing this? What am I overlooking?
YimingChen Posted - 01/20/2021 : 09:36:55 AM
Hi,

How do you want to change the data range name? The data range should have the standard Origin range format like Y: [Book1]Sheet1!B"bb"[0:0] which specifies the column you picked.

To set plot color, can you try the code below? More details can be found at: https://www.originlab.com/doc/OriginC/guide/Customizing-Data-Plots

DataPlot dp = gl.DataPlots(0);
bool bRepaint = true;
dp.SetColor(SYSCOLOR_GREEN, bRepaint);


James
hschausb Posted - 01/19/2021 : 7:17:53 PM
Thank you James. 2 and 3 worked fine for me.

May I trouble some again with some questions? I am right now using this
https://www.originlab.com/doc/OriginC/guide/Graphs
as a guid. And there is no example of how to change the name of a data range. I am using multiple data sets inside a data range. Upon adding a data set into the data range, a “Name” is assigned to the data set. Most of the time it is “A”,”B”, …..
How do I change this?

My next question would be how to change/fix the colour of a data set in a data range inbound into the Graph layer.

Thank you again for your help.
YimingChen Posted - 01/19/2021 : 2:17:42 PM
Hi,

1.

     if( gp.IsValid() )

2.

     DataRange dr;
     dr.Add("X",wksRd,-1,0,-1,0);
     dr.Add("Y",wksRd,-1,1,-1,1);
     dr.Add("Y",wksRd,-1,2,-1,2);
     gl.AddPlot( drFit, IDM_PLOT_SCATTER );


3.

    int nPlots = gl.DataPlots.Count();    
    for(int ii = 0; ii < nPlots; ii++)
        gl.RemovePlot(0);


James

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