Hi Bruce,
There are different alternatives depending on the exact requirements.
- You could add your values passing the year as label:
Code: Select all
uses Series, DateUtils;
procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
tmpDate: TDateTime;
begin
Chart1.View3D:=false;
Chart1.Legend.Visible:=false;
with Chart1.AddSeries(TPointSeries) do
begin
XValues.DateTime:=true;
Marks.Visible:=true;
tmpDate:=Today;
for i:=0 to 10 do
begin
AddXY(tmpDate, random, FloatToStr(YearOf(tmpDate)));
tmpDate:=IncYear(tmpDate);
end;
end;
Chart1.Axes.Bottom.LabelStyle:=talValue;
end;
- If you are using the label for another purpose, if the XValues contain the year you want to show in the marks, you could use that on the GetMarkText event:
Code: Select all
uses Series, DateUtils;
procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
tmpDate: TDateTime;
begin
Chart1.View3D:=false;
Chart1.Legend.Visible:=false;
with Chart1.AddSeries(TPointSeries) do
begin
XValues.DateTime:=true;
Marks.Visible:=true;
tmpDate:=Today;
for i:=0 to 10 do
begin
AddXY(tmpDate, random);
tmpDate:=IncYear(tmpDate);
end;
OnGetMarkText:=PointGetMarkText;
end;
end;
Procedure TForm1.PointGetMarkText(Sender:TChartSeries; ValueIndex:Integer; var MarkText:String);
begin
MarkText:=FloatToStr(YearOf(Sender.XValue[ValueIndex]));
end;
- If the XValues don't store the TDateTime, you can always have an array of strings to store your labels. Something like the Labels list I'm using in the first alternative above:
Code: Select all
uses Series, DateUtils;
var MyMarks: array of string;
procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
tmpDate: TDateTime;
begin
Chart1.View3D:=false;
Chart1.Legend.Visible:=false;
with Chart1.AddSeries(TPointSeries) do
begin
XValues.DateTime:=true;
Marks.Visible:=true;
SetLength(MyMarks, 10);
tmpDate:=Today;
for i:=0 to 9 do
begin
AddXY(tmpDate, random);
MyMarks[i]:=FloatToStr(YearOf(tmpDate));
tmpDate:=IncYear(tmpDate);
end;
OnGetMarkText:=PointGetMarkText;
end;
end;
Procedure TForm1.PointGetMarkText(Sender:TChartSeries; ValueIndex:Integer; var MarkText:String);
begin
MarkText:=MyMarks[ValueIndex];
end;