Page 1 of 1

Bar chart isn't in color (mostly)

Posted: Mon Aug 10, 2009 11:14 pm
by 15050460
OK, I've searched the forums & help for SetColor(), GetAsBar(), and other topics but these topics aren't there.

I am trying to plot a barchart in color, but I can't get main part of the bar-chart to plot in color. I can get the border to change colors, but not the main box of color.

I've tried every combination in the TeeChart editing dialog box Series->Series0->Format tab->Format tab to try to get any other color than black on the bar graph but no luck.

I also tried setting the color parameters during runtime but that didn't work either.

I use a very simple code on this test

Code: Select all

void CTeeChartTestDlg::OnBnClickedOk()
{
	// TODO: Add your control notification handler code here
	unsigned int i, I = 20;
	for(i=0; i<I; i++) {
		m_Chart1.Series(0).AddXY(i,i, L"", 0);
		m_Chart1.Series(1).AddXY(i, I-i, L"", 0);
	}
}
I'm using a simple non-3D graph but what I don't know what I'm missing. I've attached screenshots of the settings in the settings editor and a screenshot of what I get.

The border on series0 is not set (i.e. no boarder on series0) but you can see that the border comes out correctly on series1.

btw: For line-graphs I can get the colors to come out fine, just not bar charts.

Compiler: Visual Studio C++ 2008
TeeChart: TeeChart Pro v8 ActiveX

Re: Bar chart isn't in color (mostly)

Posted: Tue Aug 11, 2009 8:40 am
by yeray
Hi manelson,

The problem is that you are a assigning a color to each point when adding data to the series. Therefore you can not change series color if each point has been assigned a color individually.

So that it works as you request you should use clTeeColor constant as the color in the AddXY method when populating your series. Then you could set series color both at runtime or in the editor.

Re: Bar chart isn't in color (mostly)

Posted: Tue Aug 11, 2009 6:19 pm
by 15050460
Thanks, that was it.

Re: Bar chart isn't in color (mostly)

Posted: Tue Sep 01, 2009 10:51 am
by 15050347
Hi,

Could anyone assist me in the following:

I'm trying to set a specific series color, but the convention of type Color to uint isn't correct. Any suggestions?

P.S This is my code in C#

TChart.Series(0).Color = System.Convert.ToUInt32(System.Drawing.ColorTranslator.ToOle(Color.Red));

Re: Bar chart isn't in color (mostly)

Posted: Tue Sep 01, 2009 11:20 am
by yeray
Hi Otokon,

In C# it's easier:

Code: Select all

tChart1.Series[0].Color = Color.Red;

Re: Bar chart isn't in color (mostly)

Posted: Tue Sep 01, 2009 11:25 am
by 15050347
Thanks for the quick reply.

I'm getting the error "Cannot implicitly convert type 'System.Drawing.Color' to 'uint' "

That's why I'm trying to convert in to uint...? Am i missing something..?

Re: Bar chart isn't in color (mostly)

Posted: Tue Sep 01, 2009 12:01 pm
by yeray
Hi Otokon,

The following code seems to work fine in AX under C#:

Code: Select all

axTChart1.Series(0).Color = Convert.ToUInt32(ColorTranslator.ToOle(Color.Red));

Re: Bar chart isn't in color (mostly)

Posted: Tue Sep 01, 2009 12:22 pm
by 15050347
Hi Yeray,

Sorry, but I'm still in the dark. I'm using VS 2005 with TeeChart 8 ActiveX.

Here is the complete block of code I'm trying to use:

Code: Select all

TeeChart.TChart MyChart = new TeeChart.TChart();

MyChart.AddSeries(TeeChart.ESeriesClass.scBar);
MyChart.Series(0).Marks.Visible = false;
MyChart.Series(0).Pen.Visible = false;
MyChart.Series(0).asBar.MultiBar = TeeChart.EMultiBar.mbStacked;
MyChart.Series(0).asBar.BarWidthPercent = 100;


MyChart.Series(0).Color = System.Convert.ToUInt32(System.Drawing.ColorTranslator.ToOle(Color.Red));

MyChart.Series(0).AddXY(1,23,"Peter",(uint)TeeChart.EConstants.clTeeColor);

MyChart.Series(0).AddXY(1,34,"Jerry",(uint)TeeChart.EConstants.clTeeColor);
Do you spot anything wrong?

Re: Bar chart isn't in color (mostly)

Posted: Tue Sep 01, 2009 2:02 pm
by yeray
Hi Otokon,

And could you please explain what is the expected result? I can see the whole bar red with your code. I think that a picture would be very helpful.

Re: Bar chart isn't in color (mostly)

Posted: Tue Sep 01, 2009 2:18 pm
by 15050347
Hi Yeray,

The result your are getting would be the desired result. But at my side I'm not getting that same result.

I found something interesting regarding my problem I'm having. When I set a series color to a non class default color it works correctly, for example:

Code: Select all

MyChart.Series(0).Color = 254; //Works fine, and I see a red series

MyChart.Series(1).Color = 255; //Doesn't work, and series does not change to clred

Re: Bar chart isn't in color (mostly)

Posted: Tue Sep 01, 2009 2:20 pm
by 15050347
PS the 255 should first be converted to a uint.....

Re: Bar chart isn't in color (mostly)

Posted: Wed Sep 02, 2009 11:17 am
by yeray
Hi Otokon,

Are you using the latest version available (8.0.0.6)? Here using that version under VS2005 the following code shows one red bar:

Code: Select all

        private void InitializeChart()
        {
            MyChart.AddSeries(TeeChart.ESeriesClass.scBar);
            MyChart.Series(0).Marks.Visible = false;
            MyChart.Series(0).Pen.Visible = false;
            MyChart.Series(0).asBar.MultiBar = TeeChart.EMultiBar.mbStacked;
            MyChart.Series(0).asBar.BarWidthPercent = 100;

            MyChart.Series(0).Color = System.Convert.ToUInt32(System.Drawing.ColorTranslator.ToOle(Color.Blue));
            MyChart.Series(0).Color = 255;

            MyChart.Series(0).AddXY(1, 23, "Peter", (uint)TeeChart.EConstants.clTeeColor);
            MyChart.Series(0).AddXY(1, 34, "Jerry", (uint)TeeChart.EConstants.clTeeColor);
        }

Re: Bar chart isn't in color (mostly)

Posted: Thu Sep 03, 2009 8:34 am
by 15050347
Hi,

I downloaded version 8.0.0.6 and it seems to be working correctly. But now I have another question.

I have 3 bar series on my chart, the one is Color.Lime the other Color.Blue, but the one I marked with a Red circle is actually Color.Red. Why is this not 255 type Red...?
TCh.png
Color.Red not 255 type Red
TCh.png (14.09 KiB) Viewed 13513 times

Code: Select all

MyChart.Series(0).Color =System.Convert.ToUInt32(System.Drawing.ColorTranslator.ToOle(Color.Red));

Re: Bar chart isn't in color (mostly)

Posted: Thu Sep 03, 2009 8:47 am
by narcis
Hi Otokon,

I'm not able to reproduce the problem here using code snippet below. Can you please modify it or attach a simple example project we can run "as-is" to reproduce the problem here?

Code: Select all

			axTChart1.Dock = DockStyle.Fill;
			axTChart1.Aspect.View3D = false;

			for (int i = 0; i < 3; i++)
			{
				axTChart1.AddSeries(TeeChart.ESeriesClass.scBar);
				axTChart1.Series(i).asBar.BarWidthPercent = 100;
				axTChart1.Series(i).asBar.MultiBar = TeeChart.EMultiBar.mbSideAll;
				axTChart1.Series(i).asBar.BarPen.Visible = false;
				axTChart1.Series(i).Marks.Visible = false;
				axTChart1.Series(i).FillSampleValues(100);
			}

			axTChart1.Series(0).Color = System.Convert.ToUInt32(System.Drawing.ColorTranslator.ToOle(Color.Red));
			axTChart1.Series(1).Color = System.Convert.ToUInt32(System.Drawing.ColorTranslator.ToOle(Color.Blue));
			axTChart1.Series(2).Color = System.Convert.ToUInt32(System.Drawing.ColorTranslator.ToOle(Color.Lime));
Thanks in advance.