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
 DataRange issues
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

additive

Germany
109 Posts

Posted - 03/10/2010 :  12:52:26 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. 8.1 SR2
Operating System: Win XP

Hi,
I'm referring to
[url]http://ocwiki.originlab.com/index.php?title=OriginC:Column_Plot/url]

or even more simple code based on a 3-column worksheet:
void TestDataRange()
{
    WorksheetPage wksPage("Book1");
    Worksheet wks = wksPage.Layers(0);
    if( wks )
    {
        DataRange dr;
        int iXCol = 0;
        int iYCol = 1;

        dr.Add(wks, iXCol, "X", iXCol, 1, 6);
        dr.Add(wks, iYCol, "Y", iYCol, 1, 6);

        dr.Add(wks, iXCol, "X", iXCol, 10, 16);
        dr.Add(wks, iYCol, "Y", iYCol, 10, 16);

        GraphPage gp;
		gp.Create();
        GraphLayer gl = gp.Layers(0);
        if( gl.AddPlot(dr, IDM_PLOT_LINESYMB) >= 0 )
        {
            //gl.Rescale(); // magic Origin // otherwise no colors!
            const int nIndexingBegin = 100;
            int nFillColor = nIndexingBegin + 1; // column D is the 3rd Y column, Origin C index offset is 0, so add 2 here.

            gl.UngroupPlots(0);
            gl.UngroupPlots(1);

            DataPlot dp = gl.DataPlots(0);
            dp.SetColor(nFillColor, true);

            DataPlot dp2 = gl.DataPlots(1);
            dp2.SetColor(nFillColor, true);

        }
    }
}


Setting colors fails when no gl.Rescale(); is applied.
Why?

additive

Germany
109 Posts

Posted - 03/10/2010 :  12:59:10 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Next problem:

I want to plot several data points as line/symbol plot. When rows are not successive in the worksheets (which means some rows a omitted), the line gets lost in the plot. Graph option connecting over missing values does not help.

Is there a chance to do so?
This would be really great because otherwise I have to copy and paste the required data, thus producing a lot of redundant data.


void TestDataRange2()
{
    WorksheetPage wksPage("Book1");
    Worksheet wks = wksPage.Layers(0);
    if( wks )
    {
        DataRange dr;
        int iXCol = 0;
        int iYCol = 1;

        dr.Add(wks, iXCol, "X", iXCol, 1, 1);
        dr.Add(wks, iYCol, "Y", iYCol, 1, 1);

        dr.Add(wks, iXCol, "X", iXCol, 5, 5);
        dr.Add(wks, iYCol, "Y", iYCol, 5, 5);

        dr.Add(wks, iXCol, "X", iXCol, 2, 2);
        dr.Add(wks, iYCol, "Y", iYCol, 2, 2);
    
        GraphPage gp;
		gp.Create();
        GraphLayer gl = gp.Layers(0);
     	gl.AddPlot(dr, IDM_PLOT_LINESYMB);
    }
}


--Michael

Edited by - additive on 03/10/2010 1:00:50 PM
Go to Top of Page

Penn

China
644 Posts

Posted - 03/11/2010 :  05:19:08 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Michael,

For the first problem, I have tested your code and found that the invalid color index is used. In your code, nFillColor means the color index. There is an enum defined for the color in oc_sys.h. You can see that when nFillColor=101 is an invalid color index. In the example, nFillColor is used to set column D as color index, the color indices are from column D, but not nFillColor itself.

enum {
	SYSCOLOR_BLACK,	SYSCOLOR_RED,		SYSCOLOR_GREEN,		SYSCOLOR_BLUE,	SYSCOLOR_CYAN,		SYSCOLOR_MAGENTA,
	SYSCOLOR_YELLOW,SYSCOLOR_DKYELLOW,	SYSCOLOR_NAVY,		SYSCOLOR_PURPLE,SYSCOLOR_WINE,		SYSCOLOR_OLIVE,
	SYSCOLOR_DKCYAN,SYSCOLOR_ROYAL,		SYSCOLOR_ORANGE,	SYSCOLOR_VIOLET,SYSCOLOR_PINK,		SYSCOLOR_WHITE,
	SYSCOLOR_LTGRAY,SYSCOLOR_GRAY,		SYSCOLOR_LTYELLOW,	SYSCOLOR_LTCYAN,SYSCOLOR_LTMAGENTA,	SYSCOLOR_DKGRAY};

BTW, gl.Rescale() is nothing to do with SetColor here.

For the second problem, maybe you can try the following code:

void TestDataRange2()
{
	WorksheetPage wksPage("Book1");
	Worksheet wks = wksPage.Layers(0);
	if(wks)
	{
		Dataset dsX, dsY;
		dsX.Create(3,1);
		dsY.Create(3,1);
		
		int iXCol = 0;
		int iYCol = 1;
		
		dsX[0] = wks.Cell(1, iXCol);
		dsY[0] = wks.Cell(1, iYCol);
		
		dsX[1] = wks.Cell(5, iXCol);
		dsY[1] = wks.Cell(5, iYCol);
		
		dsX[2] = wks.Cell(2, iXCol);
		dsY[2] = wks.Cell(2, iYCol);
		
		string strXRange = "[??]1!"+dsX.GetName();
		string strYRange = "[??]1!"+dsY.GetName();
			
		DataRange dr;
		dr.Add( "X", strXRange);
		dr.Add( "Y", strYRange);
		
		GraphPage gp;
		gp.Create();
		GraphLayer gl = gp.Layers( 0 );
		
		int nRet = gl.AddPlot(dr, IDM_PLOT_LINESYMB);
		gl.Rescale();
	}
}


Penn
OriginLab Technical Services
Go to Top of Page

additive

Germany
109 Posts

Posted - 03/11/2010 :  06:27:41 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Penn,

thanks a lot for your quick response!

Sorry, but I cannot follow you concerning the first problem.
So let me try to explain again what I would like to do and where the problem occurs which I observered:

I want to plot a data range based on X / Y values found in Column A and B and the symbol color should be set by the color index found in column C (using SetColor argument = 101) or column D (argument = 102). Sorry, I mixed these two columns. I ensure that the third colum does not contain values above color enumaration (which is 24). As shown in http://ocwiki.originlab.com/index.php?title=OriginC:Column_Plot "color by index (of column)" requires setting the argument to 100 plus the column offset between Y column index and the column containing the color index.

So setting this color index actually works fine, as long as I add one data range only or I apply the rescale method. When I add two data ranges (as shown in my example) and omit the rescale method, only one data range is displayed in the graph, no matter I set the X axis scale accordingly or not. Only rescale will display the data points of the second data (sub) range. I suppose this is bug because the display should be refreshed automatically.

Regarding the second problem: Your suggestion looks great (btw. what's the meaning of "[??]1!" ?), but to finally succeed is there a way to combine this approach with the required color format by column index described above? I have to format each data point with an individual color (not just incrementing).

Edited by - additive on 03/11/2010 07:03:05 AM
Go to Top of Page

Penn

China
644 Posts

Posted - 03/12/2010 :  01:16:18 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Michael,

Problem 1:
In the example, there is only one plot created, and the plot is floating bar, then set column D as color index to fill these bars. In your case, there are two plots (type is line+symbol) are created in one graph layer. You could not fill color to line+symbol. This example will be suitable for your case. You can first put column C (color index in your case) to a vector, then set color to the group plot.

void TestDataRange()
{
    WorksheetPage wksPage("Book1");
    Worksheet wks = wksPage.Layers(0);
    if( wks )
    {
        DataRange dr;
        int iXCol = 0;
        int iYCol = 1;

        dr.Add(wks, iXCol, "X", iXCol, 1, 6);
        dr.Add(wks, iYCol, "Y", iYCol, 1, 6);

        dr.Add(wks, iXCol, "X", iXCol, 10, 16);
        dr.Add(wks, iYCol, "Y", iYCol, 10, 16);

        GraphPage gp;
        gp.Create();
        GraphLayer gl = gp.Layers(0);
        if( gl.AddPlot(dr, IDM_PLOT_LINESYMB) >= 0 )
        {
            gl.Rescale(); // magic Origin // otherwise no colors!

            vector<int> vColors;
            vColors.SetSize(2);

            Column colC = wks.Columns(2);
            vColors = colC.GetDataObject();  // get column C to vector

            Tree trFormat;
            trFormat.Root.Increment.LineColor.nVals = vColors;
            GroupPlot gplot = gl.Groups(0);  // get first group plot
            if(0 == gplot.UpdateThemeIDs(trFormat.Root) )    
            {
                bool bb = gplot.ApplyFormat(trFormat, true, true);    // apply theme tree
            }
        }
    }
}

If you don't want these two plots grouped, you can use the following code.

void TestDataRange()
{
    WorksheetPage wksPage("Book1");
    Worksheet wks = wksPage.Layers(0);
    if( wks )
    {
        DataRange dr;
        int iXCol = 0;
        int iYCol = 1;

        dr.Add(wks, iXCol, "X", iXCol, 1, 6);
        dr.Add(wks, iYCol, "Y", iYCol, 1, 6);

        dr.Add(wks, iXCol, "X", iXCol, 10, 16);
        dr.Add(wks, iYCol, "Y", iYCol, 10, 16);

        GraphPage gp;
        gp.Create();
        GraphLayer gl = gp.Layers(0);
        if( gl.AddPlot(dr, IDM_PLOT_LINESYMB) >= 0 )
        {
            gl.Rescale(); // magic Origin // otherwise no colors!

            vector<int> vColors;
            vColors.SetSize(2);

            Column colC = wks.Columns(2);
            vColors = colC.GetDataObject();

            gl.UngroupPlots(0);  // ungroup plots
            
            DataPlot dp = gl.DataPlots(0);
            dp.SetColor(vColors[0], true);
            
            DataPlot dp2 = gl.DataPlots(1);
            dp2.SetColor(vColors[1], true);
        }
    }
}


Problem 2:
"[??]1!" means loose dataset, which is not attached to any worksheet. To set each data point with an individual color, please refer to the following code:

void _set_color(const vector<int>& vnPoint, const vector<int>& vnColor, DataPlot& dp)
{
	if(!dp)
		return;
	
	Tree tr;
	tr.Root.Points.Point1.Index.nVal= 0;  //add tree node
	for(int ii = 0; ii < vnPoint.GetSize() && ii < vnColor.GetSize(); ii++)
	{
		string strNode = "Point"+(ii+1);
		TreeNode trPoints = tr.Root.Points;
		TreeNode trOnePoint = trPoints.GetNode(strNode);
		if(!trOnePoint)
			trOnePoint = trPoints.AddNode(strNode);
		
		trOnePoint.Index.nVal= vnPoint[ii];
		trOnePoint.Symbol.EdgeColor.nVal = vnColor[ii];
		trOnePoint.Symbol.FillColor.nVal = vnColor[ii];
	}

	int iRet = dp.UpdateThemeIDs(tr.Root);
	if(0 == iRet)
		dp.ApplyFormat(tr, true, true);
	
	return;
}


Penn
OriginLab Technical Services
Go to Top of Page

additive

Germany
109 Posts

Posted - 03/12/2010 :  05:49:18 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Penn,

fantastic ... thanks a lot! Now creating graphs is much more comfortable.

I'm sorry, but now three more questions arise:

1. How can I extent the _set_color function so that I can apply individual colors also to individual line segments? (line segment color is allowed to be the same as symbol color)

2. I tried to figure it out by myself but since all this tree properties are poorly documented I only can guess. Is there any overview available?

3. Are there any limitations set by these loose, temporary datasets in comparison to worksheet attached datasets? I suppose their scope ends when deleting all correspondig graphs?

Kind regards,

Michael
Go to Top of Page

Iris_Bai

China
Posts

Posted - 03/12/2010 :  2:27:40 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by additive

Next problem:

I want to plot several data points as line/symbol plot. When rows are not successive in the worksheets (which means some rows a omitted), the line gets lost in the plot. Graph option connecting over missing values does not help.

Is there a chance to do so?
This would be really great because otherwise I have to copy and paste the required data, thus producing a lot of redundant data.


void TestDataRange2()
{
    WorksheetPage wksPage("Book1");
    Worksheet wks = wksPage.Layers(0);
    if( wks )
    {
        DataRange dr;
        int iXCol = 0;
        int iYCol = 1;

        dr.Add(wks, iXCol, "X", iXCol, 1, 1);
        dr.Add(wks, iYCol, "Y", iYCol, 1, 1);

        dr.Add(wks, iXCol, "X", iXCol, 5, 5);
        dr.Add(wks, iYCol, "Y", iYCol, 5, 5);

        dr.Add(wks, iXCol, "X", iXCol, 2, 2);
        dr.Add(wks, iYCol, "Y", iYCol, 2, 2);
    
        GraphPage gp;
		gp.Create();
        GraphLayer gl = gp.Layers(0);
     	gl.AddPlot(dr, IDM_PLOT_LINESYMB);
    }
}


--Michael



Hi Additive,

About your "Next problem", plot selected or wanted rows from worksheet in graph, please reference to the example in following links:

Example 1, hight-light rows by sepcified condition in worksheet:
http://ocwiki.originlab.com/index.php?title=OriginC:Extract_Data_from_Worksheet

Example 2, plot the selected range of worksheet to graph:
http://ocwiki.originlab.com/index.php?title=OriginC:Data_Range%28Example%29#Plot_by_DataRange
plot_selection function.

About "apply individual colors also to individual line segments", I guess you has multiple line segments on one graph, and want to set different color for each one, right?
In fact, if fill row number data into one new worksheet, press Ctrl key and choose two discontinue ranges, like A[2]:B[6] and A[10]:B15, and click Symobal Scatter button to plot, will get a graph with two dataplots in one group, and color is different.
So, just follow the above plot by datarange example, will get this effection.
If want to set colorlist in dataplot group, you can setup this by theme tree, GetFormat and ApplyFormat.


Iris


Edited by - Iris_Bai on 03/12/2010 3:43:42 PM
Go to Top of Page

Iris_Bai

China
Posts

Posted - 03/12/2010 :  3:31:41 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by additive

Hi Penn,

fantastic ... thanks a lot! Now creating graphs is much more comfortable.

I'm sorry, but now three more questions arise:

1. How can I extent the _set_color function so that I can apply individual colors also to individual line segments? (line segment color is allowed to be the same as symbol color)

2. I tried to figure it out by myself but since all this tree properties are poorly documented I only can guess. Is there any overview available?

3. Are there any limitations set by these loose, temporary datasets in comparison to worksheet attached datasets? I suppose their scope ends when deleting all correspondig graphs?

Kind regards,

Michael



Hi Additive,

About loose dataset, please reference to Labtalk help:
http://wiki.originlab.com/~originla/wiki/index.php?title=LabTalk:Data_Types_and_Variables#Temporary_Loose_Dataset
and
http://wiki.originlab.com/~originla/wiki/index.php?title=LabTalk:Data_Types_and_Variables#Project_Level_Loose_Dataset

Please see the following example codes for temp dataset, run this function, will print out the message for successful plotting, but there is no curve on graph after running since temp dataset has been destoried at this moment.

void about_temp_dataset()
{
	Dataset dsX, dsY;
	
	// create this temporary dataset with 10 size
	dsX.Create(10); 
	dsY.Create(10);
	
	dsX.Data(1, 10 , 1);
	dsY.Data(1, 5, 0.5);
	
	/*
	// Dataset object attach to worksheet column
   // Uncomment this part and comment out the above create temp dataset codes to see the effection of the dataset attached to worksheet column.
	Worksheet wks = Project.ActiveLayer();
	if( !wks )
		return;
	dsX.Attach(wks, 0);
	dsY.Attach(wks, 1);
	*/	
	
	GraphPage gp;
	gp.Create();
	GraphLayer gl = gp.Layers(0);
	
	Curve crv(dsX.GetName(), dsY.GetName());
	int nPlot = gl.AddPlot(crv);
	DataPlot dp = gl.DataPlots(nPlot);
	if( dp )
		out_str("Plot temp dataset successfully");
	else
		out_str("Fail to plot");	
}


Iris

Edited by - Iris_Bai on 03/12/2010 4:46:45 PM
Go to Top of Page

Iris_Bai

China
Posts

Posted - 03/12/2010 :  5:01:13 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by additive

Hi Penn,

fantastic ... thanks a lot! Now creating graphs is much more comfortable.

I'm sorry, but now three more questions arise:

1. How can I extent the _set_color function so that I can apply individual colors also to individual line segments? (line segment color is allowed to be the same as symbol color)

2. I tried to figure it out by myself but since all this tree properties are poorly documented I only can guess. Is there any overview available?

3. Are there any limitations set by these loose, temporary datasets in comparison to worksheet attached datasets? I suppose their scope ends when deleting all correspondig graphs?

Kind regards,

Michael



Hi,

For point 2 above, you can use OriginObject::GetFormat method to see what properties can be access by format tree(theme tree), see Examples

Since OriginObject::GetFormat for all origin object calsses that derived from OriginObject class, not easy to improve the property list for all origin object based classes.

If want to see what properties support in graph relatied object, you can activate graph window, right click and choose Save Format as Theme..., in dialog click Edit button(one bitmap button under Cancel button), the properties of the theme tree supported, format tree in Origin C also included and can be access.


Iris
Go to Top of Page

additive

Germany
109 Posts

Posted - 03/15/2010 :  08:55:22 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:

About "apply individual colors also to individual line segments", I guess you has multiple line segments on one graph, and want to set different color for each one, right?


Yes. The color should be individual for each line segment, not just incrementing, and not set by another column but set via OriginC like done above using Point branches. Since I cannot achieve this format using the Origin GUI, I cannot set it and thus cannot get it as format. I'm looking for an equivalent to


Points
                 |--Point1
                 |   |--Symbol
                 |   |   |--Size = 8.


for setting the line segments belonging to point1, point2, etc.
Neither

trOnePoint.Line.Color.nVal = vnColor[ii];

nor structure like "Lines / Line1 / Color.nVal" is working ...
So can you please help me how to get the right property structure?
Go to Top of Page

Iris_Bai

China
Posts

Posted - 03/16/2010 :  09:46:04 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Additive,

Hope the following example help you. Run "set_specialpoints 1 2 2 5" to set properties for 2nd and 3rd points.

void set_specialpoints(int i1, int c1, int i2, int c2)
{
   GraphLayer gl = Project.ActiveLayer();
   DataPlot dp = gl.DataPlots(0);
   
   Tree tr;
   tr.Root.Points.Point1.Index.nVal=i1;// i1 is the index of this point, offset is 0
   tr.Root.Points.Point1.Symbol.Size.dVal=20;        // pts
   tr.Root.Points.Point1.Symbol.Type.nVal=0;        // geometric
   tr.Root.Points.Point1.Symbol.Shape.nVal=1;        // square
   tr.Root.Points.Point1.Symbol.Interior.nVal=0;    // solid
   tr.Root.Points.Point1.Symbol.EdgeColor.nVal=c1;
   
   tr.Root.Points.Point2.Index.nVal=i2;
   tr.Root.Points.Point2.Symbol.Size.dVal=20;        // pts
   tr.Root.Points.Point2.Symbol.Type.nVal=0;        // geometric
   tr.Root.Points.Point2.Symbol.Shape.nVal=1;        // square
   tr.Root.Points.Point2.Symbol.Interior.nVal=0;    // solid
   tr.Root.Points.Point2.Symbol.EdgeColor.nVal=c2;
   
   int iRet = dp.UpdateThemeIDs(tr.Root, "Error", "Unknown tag");
   bool bRet = dp.ApplyFormat(tr, true, true);     
}


Iris

Edited by - Iris_Bai on 03/16/2010 10:34:12 AM
Go to Top of Page

additive

Germany
109 Posts

Posted - 03/16/2010 :  12:04:04 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:

Hope the following example help you. Run "set_specialpoints 1 2 2 5" to set properties for 2nd and 3rd points.



Hi Iris,
setting the symbol format of individual data points already worked using the examples above.
My question refers to setting the line format between individual points.

Our customer wants a really special plot where each line between two data points has an individual color.

If you like I can send a sample file for illustration.

Kind regards,

Michael
Go to Top of Page

Iris_Bai

China
Posts

Posted - 03/16/2010 :  4:26:33 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Michael,

I want to know you asked is to set each line to differrent color or just set all lines to one same color? Seems not support set different color for lines in one data plot for now. Send me your illustration file will be perfect.

Anyway, here I give an example to set same color to all lines on 2-points segment plot.

void set_lines()
{
   GraphLayer gl = Project.ActiveLayer();
   DataPlot dp = gl.DataPlots(0);
 
   Tree tr; 
   tr.Root.Line.Color.nVal = 3; // set line color to blue
   
   int iRet = dp.UpdateThemeIDs(tr.Root, "Error", "Unknown tag");
   bool bRet = dp.ApplyFormat(tr, true, true);     
}


Iris

Edited by - Iris_Bai on 03/16/2010 4:30:58 PM
Go to Top of Page

additive

Germany
109 Posts

Posted - 03/17/2010 :  09:25:46 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Seems not support set different color for lines in one data plot for now



In general, it is possible using method SetColor(100+iOffsetColIndex).
So I hoped their is away to apply this on loose datasets (consisting of a collection of data points), too.


string strXRange = "[??]1!"+dsX.GetName();
string strYRange = "[??]1!"+dsY.GetName();		
DataRange dr;
dr.Add( "X", strXRange);
dr.Add( "Y", strYRange);


If is not supported by now can you add in SR3?

Edited by - additive on 03/17/2010 09:26:46 AM
Go to Top of Page

Iris_Bai

China
Posts

Posted - 03/17/2010 :  3:26:30 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

We do not support loose dataset for this case, could you tell me why use loose dataset here? If you want to hide the color data, can put color data into one column, and then hide this column. To hide column, just set the width of column to 0, Column::SetWidth(0).

Iris
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