ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Label x axis
Posted by Max on Feb-06-2024 12:44
Hi,

How can I make the format of x axis to show only hours?
But if multiple days are in the x axis, then show a date b/w each day.
If less than 24 hours, then wanted to show in hh:nn

  Re: Label x axis
Posted by Peter Kwan on Feb-06-2024 23:53
Attachments:
Hi Max,

May be you can try the Axis.setMultiFormat methods. (As I am not sure which programming language and framework you are using, I just include the links from the ChartDirector for .NET documentation.)

https://www.advsofteng.com/doc/cdnet.htm#Axis.setMultiFormat.htm

The Zooming and Scroll with Track Line (2) is an example that demonstrates these methods:

https://www.advsofteng.com/doc/cdnet.htm#zoomscrolltrack2.htm

In the sample code, the data are several years of daily data points. I modified it to use thousands hourly data points, and the effect is as shown in the image below.

The key code is:

c.xAxis().setMultiFormat(Chart.StartOfDayFilter(), "<*font=bold*>{value|hh:nn<*br*>mmm dd}", Chart.AllPassFilter(), "{value|hh:nn}");

It means if a label is the first label of a day, it will include both the hour and minutes (hh:nn) and the day and month (mmm dd). Otherwise, it will just include the hour and minutes (hh:nn). By default, this API will "promote" the first label, that means the first label will always include the day and month. So even if your data has less than 24 hours, the first label will still have the date and month. The intention is to allow the user easily know the full time of the labels. The "promotion" feature can be disabled. (See the doc on the setMuitiFormat API.)

Another issue you may consider is how you can be sure date/month and hourly labels are the option possibility? If you let ChartDirector to automatically generate the labels, depending on your data, it is possible to generate per minute or per 30 minute labels if your chart contains 120 minutes of data. It is The Axis.setMinTickInc can be used to configure minimum label spacing for automatically generated labels.

Best Regards
Peter Kwan
CSharpWinCharts_20240206232318.png