changing the color of some of the labels
changing the color of some of the labels
hi
the bottom axis contains dates. for each date i want to check if it answers a certain condition
if so, it should be blue, otherwise black.
i did the following just to check:
procedure Tfrm.Chart1GetAxisLabel(Sender: TChartAxis;
Series: TChartSeries; ValueIndex: Integer; var LabelText: String);
begin
inherited;
if not Sender.IsDateTime then exit;
if valueindex mod 2 = 0 then
sender.LabelsFont.Color := clblue
else
sender.LabelsFont.Color := clblack;
end;
but the event is not even triggered
how can i accomplish what i wrote above?
thanks
the bottom axis contains dates. for each date i want to check if it answers a certain condition
if so, it should be blue, otherwise black.
i did the following just to check:
procedure Tfrm.Chart1GetAxisLabel(Sender: TChartAxis;
Series: TChartSeries; ValueIndex: Integer; var LabelText: String);
begin
inherited;
if not Sender.IsDateTime then exit;
if valueindex mod 2 = 0 then
sender.LabelsFont.Color := clblue
else
sender.LabelsFont.Color := clblack;
end;
but the event is not even triggered
how can i accomplish what i wrote above?
thanks
Re: changing the color of some of the labels
Hello Nati,
If you want change color of labels font alternately, you can not use LabelFont so it property change color of all labels. I recommend use custom labels as do in next example:
Could you please, tell us if previous code works as you want?
I hope will helps.
Thanks,
If you want change color of labels font alternately, you can not use LabelFont so it property change color of all labels. I recommend use custom labels as do in next example:
Code: Select all
procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
dt: TDateTime;
myColor: TColor;
begin
Chart1.AddSeries(TLineSeries.Create(Self));
for i:=0 to 10 do
begin
dt:=Now + i;
Chart1[0].AddXY(dt, random, DateToStr(dt));
end;
Chart1.Axes.Bottom.Items.Clear;
for i:=0 to Chart1[0].Count-1 do
begin
if i mod 2 <> 0 then
myColor:=clRed
else
myColor:=clBlack;
Chart1.Axes.Bottom.Items.Add(Chart1[0].XValue[i], Chart1[0].Labels[i]).Format.Font.Color:=myColor;
end;
Chart1.Axes.Bottom.LabelsAngle:=90;
end;
I hope will helps.
Thanks,
Best Regards,
Sandra Pazos / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
Re: changing the color of some of the labels
hi
this is not exactly what i need.
the data is coming from a cds so at first i fill the data inside the cds and the graph is updated accordingly.
for each date value (x/bottom axis) i need to check if it answers a certain criteria and paint it accordingly.
thanks
this is not exactly what i need.
the data is coming from a cds so at first i fill the data inside the cds and the graph is updated accordingly.
for each date value (x/bottom axis) i need to check if it answers a certain criteria and paint it accordingly.
thanks
Re: changing the color of some of the labels
Hello Nati,
Could you please, try to arrange a simple example project we can run as-is to reproduce the problem here?
Thanks,
Could you please, try to arrange a simple example project we can run as-is to reproduce the problem here?
Thanks,
Best Regards,
Sandra Pazos / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
Re: changing the color of some of the labels
actually there is no problem just a question
im using TDBChart which values are coming from a cds
and the question is: how can i control the color of each label in the bottom axis
im using TDBChart which values are coming from a cds
and the question is: how can i control the color of each label in the bottom axis
Re: changing the color of some of the labels
Hello Nati,
I 'm afraid that the only way you have for controlling labels colors is using custom labels as I do in the example above.
Thanks,
I 'm afraid that the only way you have for controlling labels colors is using custom labels as I do in the example above.
Thanks,
Best Regards,
Sandra Pazos / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
Re: changing the color of some of the labels
hi
thanks, it actually seems to do the trick
thanks, it actually seems to do the trick
Re: changing the color of some of the labels
Hello Nati,
I am glad that now solution works for you .
Thanks,
I am glad that now solution works for you .
Thanks,
Best Regards,
Sandra Pazos / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
Re: changing the color of some of the labels
Hi,
However, I think that the OnGetAxisLabel event should allow you to change the labels font, and it did in v8.07.
I've added it to the defect list be investigated for future releases (TV52015315).
However, I think that the OnGetAxisLabel event should allow you to change the labels font, and it did in v8.07.
I've added it to the defect list be investigated for future releases (TV52015315).
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: changing the color of some of the labels
Hello,
Investigating this, it claimed to us that it is already possible with events too. You only have to use the axis OnDrawLabel event instead of the chart's OnGetAxisLabel.
Here it is an example of the usage:
So we've closed the ticket with number [TV52015315].
Investigating this, it claimed to us that it is already possible with events too. You only have to use the axis OnDrawLabel event instead of the chart's OnGetAxisLabel.
Here it is an example of the usage:
Code: Select all
private
{ Private declarations }
procedure OnBottomAxisDawLabel(Sender:TChartAxis; var X,Y,Z:Integer; var Text:String; var DrawLabel:Boolean);
//...
uses Series;
procedure TForm1.FormCreate(Sender: TObject);
begin
Chart1.AddSeries(TLineSeries);
Chart1[0].FillSampleValues(10);
Chart1.Axes.Bottom.OnDrawLabel:=OnBottomAxisDawLabel;
end;
procedure TForm1.OnBottomAxisDawLabel(Sender:TChartAxis; var X,Y,Z:Integer; var Text:String; var DrawLabel:Boolean);
begin
If Round(StrToFloat(Text)) mod 2 = 0 Then
Chart1.Canvas.Font.Color:=clRed
else
Chart1.Canvas.Font.Color:=clGreen;
end;
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
-
- Advanced
- Posts: 228
- Joined: Tue Aug 28, 2007 12:00 am
- Location: Oregon, USA
Re: changing the color of some of the labels
Is there any way to get the X index from the X variable (which appears to be the pixels)? The text assigned to the "Text" variable can vary.
Thank you,
Ed Dressel
Thank you,
Ed Dressel
Re: changing the color of some of the labels
Hi Ed,
I'm afraid you have to loop into your series values looking for an ValueIndex that matches with the x pixel you have
I'm afraid you have to loop into your series values looking for an ValueIndex that matches with the x pixel you have
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
-
- Advanced
- Posts: 228
- Joined: Tue Aug 28, 2007 12:00 am
- Location: Oregon, USA
Re: changing the color of some of the labels
I tried the following LOC but X never equals lSrs.CalcXPos(I) (FRedLblIndexes is a TList of integer and contain the index of values that should be drawn in red):
What should I do differently?
Ed Dressel
Code: Select all
procedure TfrmDBCalcRetirementYears.ChartBottomAxisDrawLabel(Sender:TChartAxis; var X,Y,Z:Integer; var Text:String; var DrawLabel:Boolean);
var
I: Integer;
lChart: TChart;
lIdx: Integer;
lSrs: TChartSeries;
begin
Assert(Sender.ParentChart is TChart);
lChart := TChart(Sender.ParentChart);
if lChart.SeriesCount > 0 then
begin
lSrs := lChart.Series[0];
lIdx := -1;
for I := 0 to lSrs.Count - 1 do
if lSrs.CalcXPos(I) = X then
begin
lIdx := I;
break;
end;
if (lIdx > -1) and (FRedLblIndexes.IndexOf(X) > -1) then
lChart.Canvas.Font.Color := clRed;
end;
end;
Ed Dressel
-
- Advanced
- Posts: 228
- Joined: Tue Aug 28, 2007 12:00 am
- Location: Oregon, USA
Re: changing the color of some of the labels
Attached is a demo that reproduces the problem. It appears that with a bar series, CalcXPos gives the left side of the bar and the X parameter is the center of the bar. (In the attached demo, the caption shows the X, Y position of the mouse when it is over the TChart, along with the CalcXPos and X values for Series[0]).
I am pressed to get this working.
Ed Dressel
I am pressed to get this working.
Ed Dressel
- Attachments
-
- Draw Axis Label Position.zip
- (3.01 KiB) Downloaded 807 times
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Re: changing the color of some of the labels
Hi Ed,
You can calculate bar's center position from CalcBarBounds method implementing ChartBottomAxisDrawLabel as shown below. You'll see values in both lists coinciding now.
You can calculate bar's center position from CalcBarBounds method implementing ChartBottomAxisDrawLabel as shown below. You'll see values in both lists coinciding now.
Code: Select all
procedure TForm1.ChartBottomAxisDrawLabel(Sender: TChartAxis; var X, Y,
Z: Integer; var Text: String; var DrawLabel: Boolean);
var
I : Integer;
lValue: Integer;
rect : TRect;
XPos : Integer;
begin
lValue := StrToIntDef(Text, -1);
if lValue < 0 then
begin
lbxXValues.Items.Clear;
lbxCalcXPos.Items.Clear;
for I := Series1.Count - 1 downto 0 do
begin
rect := Series1.CalcBarBounds(I);
XPos := rect.Left + ((rect.Right - rect.Left) div 2);
lbxCalcXPos.Items.Add(Format('X Pos for %d: %d', [I, XPos]));
end;
end
else
lbxXValues.Items.Add(Text + ': ' + IntToStr(X));
end;
Best Regards,
Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |