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
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Changing X data on plots question
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

kwis2

Poland
6 Posts

Posted - 10/22/2012 :  12:22:11 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hi

I have very simple question, which I can't solve....
There is a lot of graphs with data - temperature in deg C as X, and for now I need temperature in Kelvin, it mean that for some X columns in worksheets I have to add 273.15 Is there any simple way to change value of X column for every curve on graph?

Regards
Kamil

Penn

China
644 Posts

Posted - 10/22/2012 :  11:46:35 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Kamil,

The following procedure and related methods may help.

1. Get the data plot from the graph layer. DataPlots
2. Get the data from the data plot. GetDataRange, GetData
3. Add 273.15 to the X column data.
4. Set the data back to the data plot. SetData
5. Rescale and refresh the graph.

Here is the sample code:


GraphLayer gl = Project.ActiveLayer();  // get the active graph layer
if(!gl)
	return;

DataPlot dp = gl.DataPlots(0);  // get the first (zero-based) data plot from the graph layer
XYRange xy; 
if(dp.GetDataRange(xy))  // get the xy range from the data plot
{
	vector vX, vY;
	if(xy.GetData(vY, vX))  // get the xy data from the xy range
	{
		vX = vX+273.15;  // change x vector by adding 273.15
		xy.SetData(&vY, &vX);  // set the changed data back to xy range
	}
}
gl.Rescale();  // rescale the graph layer
gl.GetPage().Refresh();  // refresh the graph page


Penn
Go to Top of Page

kwis2

Poland
6 Posts

Posted - 10/23/2012 :  02:53:43 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Penn

It was so easy ;)

I have tried to find way around - to list dataPlots, worksheetPages and I have failed to find proper worksheet correspond to plot, to modify data ...

BTW I am just beginner in OriginC programming. Do you know any document where there will be all OriginC functions listed? Just cheatsheet? I use Origin with University licence, so in fact I have no documentation available.

Best regards
Kamil
Go to Top of Page

Penn

China
644 Posts

Posted - 10/23/2012 :  03:23:47 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Kamil,

To learn Origin C, you can refer to Origin C page.

Penn
Go to Top of Page

rlewis

Canada
253 Posts

Posted - 10/23/2012 :  03:30:23 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Try Something like ...

void ModifyXData()
{
	GraphLayer gl = Project.ActiveLayer();  // get the active graph layer
	if(!gl)
	return;
	foreach (DataPlot dp in gl.DataPlots)
	{
		XYRange xy; 
		if(dp.GetDataRange(xy))  // get the xy range from the data plot
		{
			vector vX, vY;
			if(xy.GetData(vY, vX))  // get the xy data from the xy range
			{
				vX = vX+273.15;  // change x vector by adding 273.15
				xy.SetData(&vY, &vX);  // set the changed data back to xy range
			}
		}
	}
	gl.Rescale();  // rescale the graph layer
	gl.GetPage().Refresh();  // refresh the graph page
}
Go to Top of Page

kwis2

Poland
6 Posts

Posted - 10/24/2012 :  02:47:44 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Program work fine , once again thank you for your help.

Ocwki is OK, but I am looking for some kind of one sheet cheatsheet with listed classes, methods and etc.
For instance, from the beginning I lost some time to correct error:
wks.Column(...) and I have received error "Error, Member function Worksheet::Column not defined or does not have matching prototype." Finally I have found !! he looks for one letter "s" and there should be wks.Columns(...).
I know it is begginers problem, and with time cheatsheet won't be necessary, but for now it would be very usefull.

Best regards
Kamil
Go to Top of Page

rlewis

Canada
253 Posts

Posted - 10/24/2012 :  03:34:25 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
The closest thing to an OriginC Cheat Sheet is of the the On-Screen variety under the Origin Help menu..

Help -> Progamming-> OriginC .... then look under OriginC reference tab and all such things will be revealed unto you ...
Go to Top of Page

kwis2

Poland
6 Posts

Posted - 10/24/2012 :  4:38:20 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi
I have another problem.
I need to add one more column of data to worksheet.
I use Penn code, and I have tried to add one more column:

if(dp.GetDataRange(xy))  // get the xy range from the data plot
{
   xy.GetDatasetNames(strY, strX);
			
   int nPos = strY.Find('_');
   
   if(nPos > 0)
      string strWksName = strY.Left(nPos);

      Worksheet currWks(strWksName);
      currWks.AddCol("newCol");
      ......
}



It works only if I have only one layer in worksheet. In fact I have no idea how to solve problem

Best regards
Kamil
Go to Top of Page

Penn

China
644 Posts

Posted - 10/26/2012 :  03:52:52 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Kamil,

You can use the GetBookSheet method instead. For example:

if(dp.GetDataRange(xy))  // get the xy range from the data plot
{
	string strBook, strSheet;
	if(xy.GetBookSheet(strBook, strSheet))
	{
		Worksheet currWks("[" + strBook + " ]" + strSheet + "!");
		currWks.AddCol("newCol");
		currWks.GetPage().Refresh();

	}
}


Penn

Edited by - Penn on 10/26/2012 03:56:20 AM
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000