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
 colors in bargraph according to column names
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

ingogermany

Germany
5 Posts

Posted - 01/04/2010 :  05:06:26 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): 7.5 SR4
Operating System: Windows XP

A big "THANK YOU ALL" for this great Forum with good answers on nearly every problem i had, but not this one (or i am too tired to find it here):

is there a possibility, to make a colormap with an if structure? I want to give every element its own color, for example element C is black, element N (for Nitrogen) is red and so on. I have different worksheets with a changing number of columns and varying elements. The elements are the names of the columns.
At the moment, i get different colorbars with the right different colors with a theme i stored, but if i vary my elements with new ones, this does not work. I need something like a big element list with the exact colors connected.

something like this (only the structure, not code):
if columnname=C --> black bar;

where is the connection in originC to realize this, is it the tree?

Can someone give me a hint to solve this?
Thank you for your help in advance!

Penn

China
644 Posts

Posted - 01/05/2010 :  05:42:52 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

Maybe it is not easy to satisfy your above requirement in Origin 7.5. However, with Origin 8 and Origin 8.1, you can access the format of the grouped plots to do it.

Please refer to this example.

Penn
OriginLab Technical Services

Edited by - Penn on 01/05/2010 05:44:06 AM
Go to Top of Page

ingogermany

Germany
5 Posts

Posted - 01/05/2010 :  10:54:19 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you for your fast answer. Since we won't upgrade the software to version 8 soon, i am still hoping for a solution for version 7.5...

the command SYSCOLOR_BLACK for example is not found from my compiler.
--> Error, Variable "SYSCOLOR_BLACK" not declared

Greetings from Greifswald
Go to Top of Page

ingogermany

Germany
5 Posts

Posted - 01/05/2010 :  12:10:09 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Just found something which mike buess programmed and changed it a little. Now i can give every line a defined color, 0 for black 1 for red and so on, like in the origin color list. the important command is:

grlay.DataPlots(i-1).SetColor(i-1);
if you change it into
grlay.DataPlots(i-1).SetColor(22);

every line is now "magenta light", like the 22. place in color list.
so in all i have now the following code which works, but not if i change to IDM_PLOT_COLUMNS. Then every bar is simply black.






Worksheet wssData= Project.ActiveLayer();
GraphPage gpg;
gpg.Create();
GraphLayer grlay= gpg.Layers();
for(int i = 1; i < wssData.GetNumCols(); i++) //plot each column of data
{
Curve cv(wssData,i);
grlay.AddPlot(cv, IDM_PLOT_LINE);

//test, if string "C " is there
char *testC=strstr(nameofcolumn,"C ");
if(testC!=NULL)
{
grlay.DataPlots(i-1).SetColor(1); // plot color , now C is red
};
char *testC=strstr(nameofcolumn,"N ");
if(testC!=NULL)
{
grlay.DataPlots(i-1).SetColor(2); // plot color , now N is green
};

//and so on...
grlay.Rescale();
}
}


Perhaps you cannot change the color wit .SetColor if you use COLUMN?
Go to Top of Page

Penn

China
644 Posts

Posted - 01/06/2010 :  12:59:34 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Greifswald,

The example about setting grouped bars colors has been updated, now it works in Origin 7.5, and you can try again.

From the code you posted, the bar plots created are not grouped. So, you can try using the theme tree to set color. You can change your code like below:

Worksheet wssData= Project.ActiveLayer();
GraphPage gpg;
gpg.Create();
GraphLayer grlay= gpg.Layers();
for(int i = 1; i < wssData.GetNumCols(); i++) //plot each column of data
{
	Curve cv(wssData,i);
	//grlay.AddPlot(cv, IDM_PLOT_LINE);
	grlay.AddPlot(cv, IDM_PLOT_COLUMN);
	
	//test, if string "C " is there
	char *testC=strstr(nameofcolumn,"C ");
	if(testC!=NULL)
	{
		//grlay.DataPlots(i-1).SetColor(1); // plot color , now C is red
		DataPlot dp = grlay.DataPlots(i-1); // get current data plot
		Tree trFormat;
		trFormat = dp.Curve;   // get plot's theme tree
		trFormat.Pattern.Fill.FillColor.nVal = 1;  // set fill color to theme tree
		dp.Curve = trFormat;  // set theme tree back to data plot
	};
	char *testC=strstr(nameofcolumn,"N ");
	if(testC!=NULL)
	{
		//grlay.DataPlots(i-1).SetColor(2); // plot color , now N is green
		DataPlot dp = grlay.DataPlots(i-1);
		Tree trFormat;
		trFormat = dp.Curve;
		trFormat.Pattern.Fill.FillColor.nVal = 2;
		dp.Curve = trFormat;
	};
	
	//and so on...
	grlay.Rescale();
}


Penn
OriginLab Technical Services

Edited by - Penn on 01/06/2010 04:23:15 AM
Go to Top of Page

ingogermany

Germany
5 Posts

Posted - 01/15/2010 :  09:59:03 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you Penn and OriginLab Technical Services, i found the time to program now and solved the problem with your code! i use the following code which is yours, only light varied. call it with bar_color_map() in your code after graph is created. Greetings from the town Greifswald in Germany , it is not my name

void bar_color_map()
{
GraphLayer gl = Project.ActiveLayer(); // get active graph layer
GroupPlot gpl = gl.Groups(0); // get first grouped plots

vector<int> vcColors;
int nPlotCount = gl.DataPlots.Count(); // get number of plots
vcColors.SetSize(nPlotCount); // set vector size
for(int i=0; i<nPlotCount; i++) // set color vector according to the column name
{
DataPlot dp = gl.DataPlots(i); // get dataplot
string strDatasetName = dp.GetDatasetName();
string strColName= strDatasetName.GetToken(1, '_');
printf("\n %s", strDatasetName.GetToken(1, '_'));

if(0 == strColName.Compare("C")) // set color value one by one
vcColors[i] = 0; // 0 = black
else if((0 == strColName.Compare("N"))||(0 == strColName.Compare("NC")))
vcColors[i] = 2; // 2 = grn
else if((0 == strColName.Compare("O"))||(0 == strColName.Compare("OC")))
vcColors[i] = 3; // 3 = blau
else if((0 == strColName.Compare("Al"))||(0 == strColName.Compare("AlC")))
vcColors[i] = 17; // 17 = weiss
else if((0 == strColName.Compare("Cl"))||(0 == strColName.Compare("Cl")))
vcColors[i] = 9; // 9 = lila
else if((0 == strColName.Compare("F"))||(0 == strColName.Compare("FC")))
vcColors[i] = 1; // 1 = rot
else if((0 == strColName.Compare("Si"))||(0 == strColName.Compare("SiC")))
vcColors[i] = 7; // 7 = dunkelgelb
else if((0 == strColName.Compare("Y"))||(0 == strColName.Compare("YC")))
vcColors[i] = 11; // 11 = oliv
else if((0 == strColName.Compare("Zr"))||(0 == strColName.Compare("ZrC")))
vcColors[i] = 10; // 10 = braun
else if((0 == strColName.Compare("Na"))||(0 == strColName.Compare("NaC")))
vcColors[i] = 4; // 4 = cyan
else
{vcColors[i] = 14; printf("bitte noch eigene Farbe zuweisen zu orangenem Element"); // 14 = orange
}
}

gpl.Increment.BackgroundColor.nVals = vcColors; // set increment colors

}
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