[Lazarus] TAChart Date Axis Remove Weekends

Werner Pamler werner.pamler at freenet.de
Sun Sep 14 11:57:26 CEST 2014

Don't use the real date as x value. Instead, use a counter value that is 
incremented every time you add a value to the series. Don't add data if 
the "DayOfWeek" of their date is 6 (Friday) or 7 (Saturday). In the data 
you posted in your previous message the weekends are already messing, 
therefore you can simply use the line index I for the x coordinate of 
the data point.

The problem left is the display of the axis labels. Your code in the 
other posting already adds a data label to each series point (last 
parameter of AddXOHLC shown). To activate it set the Style of the 
Chart.BottomAxis.Marks to smsLabel, and don't forget to link the 
ListSource of the series (that's where your AddXOHLC data go to) to the 
Source of the BottomAxis.Marks.

However, the x labels will be quite crowded and overlapping. There are 
several ways to get rid of that: Use some logics in creating the data 
labels - for example, if you want labels only for Monday set the 
DateToStr(lDate) to the data label only if the DayOfWeek(lDate) is 2 
(Monday), and use an empty string otherwise. Or you can play with the 
Intervals property of the BottomAxis to increase the distance of the 
labels, e.g. Intervals.MinLength=100, Intervals.MaxLength=200. Or you 
can rotate the label by 90 degrees 
(BottomAxis.Marks.LabelFont.Orientation = 900)

More information about the Lazarus mailing list