Page 1 of 1
Weeknum functionality
Posted: Thu Nov 10, 2011 12:38 pm
by 16560162
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
Re: Weeknum functionality
Posted: Thu Nov 10, 2011 3:52 pm
by yeray
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".
Re: Weeknum functionality
Posted: Thu Nov 10, 2011 3:59 pm
by narcis
Hi Peters,
For completeness, you may use
DateUtils.WeekOfTheYear method for that.
Re: Weeknum functionality
Posted: Thu Nov 10, 2011 9:00 pm
by 16560162
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
Re: Weeknum functionality
Posted: Fri Nov 11, 2011 1:32 pm
by yeray
Hi Peters,
I've added it to the wish list to be implemented in future releases (TV52015832).
Re: Weeknum functionality
Posted: Sat Nov 12, 2011 10:00 am
by 16560162
Hi,
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;
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
Re: Weeknum functionality
Posted: Sun Nov 13, 2011 8:16 pm
by 16560162
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
Re: Weeknum functionality
Posted: Tue Nov 15, 2011 4:39 pm
by yeray
Hello Peters,
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
The second option is the one I think could be interesting. It will be considered when TV52015832 will be deeply studied.
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;