Hi,
Does TeeChart support weeknum date format in chart settings? I have weekly collected data and I want to label my X-axis as
01/2011, 02/2011 etc.
where first number is a week number in the year.
Thanks
Peters
Weeknum functionality
Re: Weeknum functionality
Hi Peters,
I'm afraid it's not supported automatically. But you can always format the axis labels at OnDrawLabel event as in the example at "All features\Welcome !\Axes\First and Last Labels".
I'm afraid it's not supported automatically. But you can always format the axis labels at OnDrawLabel event as in the example at "All features\Welcome !\Axes\First and Last Labels".
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Re: Weeknum functionality
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 |
Re: Weeknum functionality
Thanks for suggestions.
Maybe in the next releases you will consider something like ''ww/yyyy" in date formating options. It would be useful improvement .
Peters
Maybe in the next releases you will consider something like ''ww/yyyy" in date formating options. It would be useful improvement .
Peters
Re: Weeknum functionality
Hi Peters,
I've added it to the wish list to be implemented in future releases (TV52015832).
I've added it to the wish list to be implemented in future releases (TV52015832).
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: Weeknum functionality
Hi,
I have almost found a solution which looks like this:
The problem is that instead of LableText I need original X-axis value, because LabelText is ALREADY formated and StrToDate returns error during convertion. So my question is how to get here oryginal bottom axis value BEFORE formating.
Thanks
Peters
I have almost found a solution which looks like this:
Code: Select all
procedure TMyChart.ChartGetAxisLabel(Sender: TChartAxis;
Series: TChartSeries; ValueIndex: Integer; var LabelText: String);
const
WW = 'ww';
var
WeekNum : string;
begin
if Sender.IsDateTime and (pos(WW, Sender.DateTimeFormat) > 0) then
try
WeekNum := IntToStr(WeekOfTheYear(StrToDate(LabelText)));
except
WeekNum := 'ERR';
end;
LabelText := StringReplace(LabelText, WW, WeekNum, [rfReplaceAll]);
end;
Thanks
Peters
Re: Weeknum functionality
Hi,
I have dug a little in the source code and I think I have a solution, but it would require changes in source code of TeEngine. Date formatting is done in LabelValue function. It gets its parameter (date value for x-label tick) from DoDeaultLabels procedure, but actual x-value is stored only in temporary tmpValue variable which is not published. So now I can see 3 solutions:
1) publish tmpValue as a property and than us it in OnGetAxisLabel
2) overwrite LabelValue function with code from my previous post
3) overwrite DateTimeToString standard VCL function and implement there the interpretation of "ww" formatting
Because of compatibility with next releases all of them are not safe. Maybe anyone has better idea? .
Thanks
Peters
I have dug a little in the source code and I think I have a solution, but it would require changes in source code of TeEngine. Date formatting is done in LabelValue function. It gets its parameter (date value for x-label tick) from DoDeaultLabels procedure, but actual x-value is stored only in temporary tmpValue variable which is not published. So now I can see 3 solutions:
1) publish tmpValue as a property and than us it in OnGetAxisLabel
2) overwrite LabelValue function with code from my previous post
3) overwrite DateTimeToString standard VCL function and implement there the interpretation of "ww" formatting
Because of compatibility with next releases all of them are not safe. Maybe anyone has better idea? .
Thanks
Peters
Re: Weeknum functionality
Hello Peters,
In the meanwhile, what about using Custom Labels?
The second option is the one I think could be interesting. It will be considered when TV52015832 will be deeply studied.peters wrote:1) publish tmpValue as a property and than us it in OnGetAxisLabel
2) overwrite LabelValue function with code from my previous post
3) overwrite DateTimeToString standard VCL function and implement there the interpretation of "ww" formatting
In the meanwhile, what about using Custom Labels?
Code: Select all
uses Series, DateUtils;
procedure TForm1.FormCreate(Sender: TObject);
var i, last: Integer;
tmpDate: TDateTime;
diff: Double;
begin
Chart1.View3D:=false;
Chart1.Legend.Visible:=false;
Chart1.Axes.Bottom.LabelsAngle:=90;
Chart1.Axes.Bottom.DateTimeFormat:='ww/yyyy';
with Chart1.AddSeries(TFastLineSeries) as TFastLineSeries do
begin
XValues.DateTime:=true;
tmpDate:=StrToDateTime('01/01/2011');
AddXY(tmpDate, random*100);
for i:=0 to 20 do
begin
tmpDate:=IncDay(tmpDate,7);
AddXY(tmpDate, YValue[Count-1] + random*10-5);
end;
Chart1.Axes.Bottom.Increment:=DateTimeStep[dtOneWeek];
Chart1.Axes.Bottom.Items.Clear;
Chart1.Axes.Bottom.Items.Add(XValue[0],StringReplace(FormatDateTime(Chart1.Axes.Bottom.DateTimeFormat,XValue[0]), 'ww', IntToStr(WeekOfTheYear(XValue[0])), [rfReplaceAll]));
last:=0;
for i:=1 to Count-1 do
begin
if (XValue[i]-XValue[last] >= Chart1.Axes.Bottom.Increment) then
begin
Chart1.Axes.Bottom.Items.Add(XValue[i],StringReplace(FormatDateTime(Chart1.Axes.Bottom.DateTimeFormat,XValue[i]), 'ww', IntToStr(WeekOfTheYear(XValue[i])), [rfReplaceAll]));
last:=i;
end;
end;
end;
end;
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |