amcharts4 icon indicating copy to clipboard operation
amcharts4 copied to clipboard

How to set start day of the week when formatting for week numbers

Open jimmykane opened this issue 3 years ago • 8 comments

I tend to format for weeks aggragate data.

How can I set the starting weekday when formatting with ww YYY for example date objects (DateAxis)

jimmykane avatar Jul 08 '20 18:07 jimmykane

There's no way to do that, I'm afraid.

The common notion is that the week of the first Wednesday in the year is the first week of that year.

martynasma avatar Jul 09 '20 07:07 martynasma

I don't argue about that, but to take into consideration if the users week starts on Monday or Sunday.

People in US have their weeks starting in Sundays.

Do you understand what I ask ?

On Thu, 9 Jul 2020, 09:39 Martynas Majeris, [email protected] wrote:

There's no way to do that, I'm afraid.

The common notion is that the week of the first Wednesday in the year is the first week of that year.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/amcharts/amcharts4/issues/2682#issuecomment-655960313, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJVX44FBA7HV4P5KSCKMW3R2VXZPANCNFSM4OU27OZA .

jimmykane avatar Jul 09 '20 11:07 jimmykane

I do. Thought week of year is not being counted based on it's beginning, but rather one fixed day - Thursday (I'm sorry I was wrong in my first reply about it being Wed).

It's actually an ISO standard: https://en.wikipedia.org/wiki/ISO_week_date#First_week

martynasma avatar Jul 09 '20 12:07 martynasma

@martynasma the first week is determined by the Thursday.

However it lasts till Sun OR Monday. Then from that the week number is determined

This is what I am asking https://en.wikipedia.org/wiki/ISO_week_date#Other_week_numbering_systems

I am very familiar with the ISO's sorry if I was not clear.

jimmykane avatar Jul 09 '20 13:07 jimmykane

Gotcha. We will consider this. But can't promise anything right now :/

In the interim, I think the immediate solution would be to use adapters to calculate your own week number on axis labels.

martynasma avatar Jul 09 '20 13:07 martynasma

We will consider this.

Take your time no rush. I was only asking if there was a way and looks like you provided one.

Thanks so much for your time

jimmykane avatar Jul 09 '20 14:07 jimmykane

Hi @jimmykane

Have the same issue. Can you explain how you implemented a workaround?

I understand there are 2 things here

  1. Logic for grouping into weeks (Sunday to Saturday)
  2. Applying aggregation on top of it

I have an adapter set to compute custom aggregation but I am not able to define a custom grouping

rejochandran avatar Mar 25 '21 08:03 rejochandran

Gotcha! Was able to fix this by specifying the firstDayOfWeek property of dateFormatter in the dateAxis

dateAxis.dateFormatter.firstDayOfWeek = 0;  
// 0 - Sunday as the first day of the week

Ref: https://www.amcharts.com/docs/v4/reference/dateformatter/#firstDayOfWeek_property

Thank you!

rejochandran avatar Mar 25 '21 09:03 rejochandran