Hi,
cristian wrote:I'm really inserting labels in all series and the series have different values of X from each other. The X values of the series are not incremented accordingly. I would like to show in the lower graph the label and the higher value (regardless of which series may be). Between the lowest and the highest value I want the labels are automatically generated for the user to orient the chart. Is there a feature to help with this?
Having labels in your series, if the bottom axis LabelStyle is set to talAuto as per default, it will show all the series labels. In that case you should implement some anti overlapping system.
Find below a simple example that reproduces the problem and fixes it. Disable OnGetAxisLabel event to see the problem.
Code: Select all
uses Series;
procedure TForm1.FormCreate(Sender: TObject);
var i, j: Integer;
begin
Chart1.View3D:=false;
Chart1.AddSeries(TFastLineSeries).FillSampleValues(20);
Chart1.AddSeries(TFastLineSeries).FillSampleValues(25);
for i:=0 to 1 do
with Chart1[i] as TFastLineSeries do
for j:=0 to Chart1[i].Count-1 do
Labels[j]:=FormatFloat('#0.##', Chart1[i].XValue[j]);
Chart1.OnGetAxisLabel:=AxisGetAxisLabel;
end;
procedure TForm1.AxisGetAxisLabel(Sender:TChartAxis; Series:TChartSeries; ValueIndex:Integer; var LabelText:String);
var i, lXPos, lWidth, tmpWidth: Integer;
XVal: Double;
item: TAxisItem;
lRect, tmpRect: TRect;
begin
if (Sender=Chart1.Axes.Bottom) and
(Series<>nil) and (ValueIndex>-1) and (ValueIndex<Series.Count) then
begin
XVal:=Series.XValue[ValueIndex];
lXPos:=Sender.CalcXPosValue(XVal);
lWidth:=Chart1.Canvas.TextWidth(LabelText);
lRect:=Rect(lXPos-(lWidth div 2), 0, lXPos-(lWidth div 2)+lWidth, 10);
for i:=0 to Sender.Items.Count-1 do
begin
item:=Sender.Items[i];
tmpWidth:=Chart1.Canvas.TextWidth(item.Text);
tmpRect:=Rect(item.LabelPos-(tmpWidth div 2), 0, item.LabelPos-(tmpWidth div 2)+tmpWidth, 10);
if (TeeRectIntersects(lRect, tmpRect)) then
begin
LabelText:='';
exit;
end;
end;
end;
end;
Another alternative is to force the axis to show values instead of the series labels:
Code: Select all
Chart1.Axes.Bottom.LabelStyle:=talValue;