Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Set TChart LineSeries Color



Permlink Replies: 5 - Last Post: Sep 5, 2016 12:41 AM Last Post By: Yeray Alonso
Carel Minnaar

Posts: 2
Registered: 10/15/11
Set TChart LineSeries Color
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 31, 2016 8:26 PM
I am writing an application in Delphi using a "TabbedwithNavigation" blank project. I am trying to plot a series on a TChart, but I want to create the series using code and I want to change the Colour of the LineSeries, but for some reason I can't. I am using a Trial version of RAD Studio 10.1 Berlin, I am used working in XE5 and the Lazarus IDE.

My sample code looks as follow:
var
MySeries1 : TLineSeries;
k : integer;
begin
MySeries1 := TLineSeries.Create(Chart1);

for k := 1 to 2000 do
begin
MySeries1.AddXY(k,k);
end;
Chart1.AddSeries(MySeries1);

Chart1.Series[0].Color := $FF; //Wipes MySeries1 from Chart1 ???
MySeries1.SeriesColor := clRed; //Gives "Undeclared Identifier clRed" ???
MySeries1.SeriesColor := $FF; ////Wipes MySeries1 from Chart1 ???
end;

I just simply cannot get the colour to change to Red, no matter what I do. Trying to change the colour just clears the whole LineSeries from Chart1. Why?
Using MySeries1.SeriesColor := clRed; works perfectly in Lazarus and in previous versions of Delphi, what has changed? I can't seem to find any documentation on this. It's weird.

Alternatively (as a workaround), I can create the Series1, Series2, etc manually by double clicking Chart1, but then how do I change the name of Series1, Series2 to MyOwnSeriesName1, MyOwnSeriesName2 ?

Kind Regards,
Carel
Andrew Law

Posts: 74
Registered: 11/6/02
Re: Set TChart LineSeries Color
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 1, 2016 3:33 AM   in response to: Carel Minnaar in response to: Carel Minnaar
Carel Minnaar wrote:

MySeries1 := TLineSeries.Create(Chart1);

What does Chart1.SeriesCount return immediately after this line? I suspect that MySeries1 is already the first series of your chart.

Chart1.AddSeries(MySeries1);

What does Chart1.SeriesCount return now? I think you have just added the same series to your chart, so now it has two series that are in fact both the same series. Try commenting out the line above and see what difference this makes.
Lajos Juhasz

Posts: 801
Registered: 3/14/14
Re: Set TChart LineSeries Color
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 1, 2016 6:27 AM   in response to: Carel Minnaar in response to: Carel Minnaar
Carel Minnaar wrote:


I just simply cannot get the colour to change to Red, no matter what
I do. Trying to change the colour just clears the whole LineSeries
from Chart1. Why? Using MySeries1.SeriesColor := clRed; works
perfectly in Lazarus and in previous versions of Delphi, what has
changed? I can't seem to find any documentation on this. It's weird.

The clRed is still definied in Vcl.Graphics. The only change is that
you can also use TColors.Red definied in System.UITypes.
Carel Minnaar

Posts: 2
Registered: 10/15/11
Re: Set TChart LineSeries Color
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 3, 2016 5:07 PM   in response to: Lajos Juhasz in response to: Lajos Juhasz
Lajos Juhasz wrote:
Carel Minnaar wrote:


I just simply cannot get the colour to change to Red, no matter what
I do. Trying to change the colour just clears the whole LineSeries
from Chart1. Why? Using MySeries1.SeriesColor := clRed; works
perfectly in Lazarus and in previous versions of Delphi, what has
changed? I can't seem to find any documentation on this. It's weird.

The clRed is still definied in Vcl.Graphics. The only change is that
you can also use TColors.Red definied in System.UITypes.

Hi, thanks for the reply. I've replicated an issue on another machine where the series name will not change, but luckily it is still possible to change the Series name in the object inspector. When not using the Object inspector, there is a bug in Berlin that will prevent the user from changing the Series name: https://quality.embarcadero.com/browse/RSP-15746

Anyways, if clRed is still definied in Vcl.Graphics, how do I use it? My application is a Multi-Device Application with aTbbedFormwithNavigation (FMX), not Vcl.

How can I still use clRed? I am new to FMX and Multi-Device Applications, I am used to Vcl and now suddenly I don't know what's going on with even the slightest things. I really need help just for a starter.

In Vcl I am also used to Label1.Font.Color := clRed;

It does not work in FMX, I needed to do:
Label1.StyledSettings := Label1.StyledSettings - [TStyledSetting.FontColor];
Label1.TextSettings.FontColor := TAlphaColors.Red;

If someone did not tell me this I would've never known it. I also cannot find details / tutorials on how to work with FMX. In Delphi 7, the Help file was very detailed.

Thanks for the help thusfar.
Yeray Alonso

Posts: 75
Registered: 6/12/11
Re: Set TChart LineSeries Color
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 5, 2016 12:38 AM   in response to: Carel Minnaar in response to: Carel Minnaar
Carel Minnaar wrote:
Anyways, if clRed is still definied in Vcl.Graphics, how do I use it? My application is a Multi-Device Application with aTbbedFormwithNavigation (FMX), not Vcl.

How can I still use clRed? I am new to FMX and Multi-Device Applications, I am used to Vcl and now suddenly I don't know what's going on with even the slightest things. I really need help just for a starter.

In Vcl I am also used to Label1.Font.Color := clRed;

It does not work in FMX, I needed to do:
Label1.StyledSettings := Label1.StyledSettings - [TStyledSetting.FontColor];
Label1.TextSettings.FontColor := TAlphaColors.Red;

If someone did not tell me this I would've never known it. I also cannot find details / tutorials on how to work with FMX. In Delphi 7, the Help file was very detailed.

Look at the documentation here :
The names of the Alpha colors constants are composed of the cla prefix and the color names defined by the TAlphaColorRec record.

So you can use claRed in FMX.

--
Best Regards,

Yeray Alonso
Steema Software
Facebook, Twitter, GPlus, LinkedIn, YouTube, GitHub, RSS
Support Options
Yeray Alonso

Posts: 75
Registered: 6/12/11
Re: Set TChart LineSeries Color
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 2, 2016 3:04 AM   in response to: Carel Minnaar in response to: Carel Minnaar
Hi Carel,

Carel Minnaar wrote:
My sample code looks as follow:
var
MySeries1 : TLineSeries;
k : integer;
begin
MySeries1 := TLineSeries.Create(Chart1);

for k := 1 to 2000 do
begin
MySeries1.AddXY(k,k);
end;
Chart1.AddSeries(MySeries1);

Chart1.Series[0].Color := $FF; //Wipes MySeries1 from Chart1 ???
MySeries1.SeriesColor := clRed; //Gives "Undeclared Identifier clRed" ???
MySeries1.SeriesColor := $FF; ////Wipes MySeries1 from Chart1 ???
end;

There are many points to clearly see the line color in the default 3D perspective, so I'd change to 2D.
However, I can't reproduce any of the three problems you mention with RAD Studio 10.1 Berlin and the TeeChart Standard version shipped with it.

Carel Minnaar wrote:
It's weird.

I agree. I'd suggest you to reinstall/repair the IDE, or do you have access to a second machine to give it another try?

Carel Minnaar wrote:
Alternatively (as a workaround), I can create the Series1, Series2, etc manually by double clicking Chart1, but then how do I change the name of Series1, Series2 to MyOwnSeriesName1, MyOwnSeriesName2 ?

After creating a series in the editor, you can select it and the "Title..." button at the right should be active.
You can also activate "View Series Names" in the dropdown on the top and the "Title..." button changes to "Name..." button enabling you to change the name of the variable.


--
Best Regards,

Yeray Alonso
Steema Software
Facebook, Twitter, GPlus, LinkedIn, YouTube, GitHub, RSS
Support Options

Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02