Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2014-09

TAChart Date Axis Remove Weekends

5 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Werner Pamler

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)

Reply by email

Leonardo M. Ramé
to Werner Pamler
Werner Pamler wrote 25 lines
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)

Thanks! Werner, the chart is starting to look very good.

Now, I need to define the range of left axis. By default it starts on 0 (bottom left) and ends in the highest value of my data. How can I change the starting value, to the minimum value of the data source?.

Currently all the data poins are displayed at the top part of the chart, and from 0 to 70 is empty.

Reply by email

Werner Pamler

I don't know, at the moment, where the minimum is forced to 0 - normally this does not happen, it is probably a bug with the multi-value series which I don't use that much, I don't know...

Until this is fixed you have to determine the minimum of the y axis on your own. Declare a variable "mn: Double", set it to a very large value before you begin reading data ("mn := 1E308"), and then, each time after adding a value to the series, compare the currently added Low-value (it should be the smallest one of this record) with the current mn value and update it: "if lLow < mn then mn := lLow".

At the end, use the Chart's Extent property to force the yMin to the
final result obtained for mn: "Chart1.Extent.YMin := mn". And this
setting has to be activated by setting the Extent's UseYMin to true:
"Chart1.Extent.UseYMin := true".

Reply by email

Leonardo M. Ramé
to Leonardo M. Ramé: Thanks! Werner, the chart is starting to look very good. Now, I need to define the range…
"Leonardo M. Ram?" wrote 37 lines
On 14/09/14 06:57, Werner Pamler wrote: > 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) > > Thanks! Werner, the chart is starting to look very good. Now, I need to define the range of left axis. By default it starts on 0 (bottom left) and ends in the highest value of my data. How can I change the starting value, to the minimum value of the data source?. Currently all the data poins are displayed at the top part of the chart, and from 0 to 70 is empty.

Please forget about this, solved by setting Chart1.Extent.UseYMax and UseYMin.

Regards,

Reply by email