Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bar chart: monthly scale off by 1 into the future, and 11/23 is shown as 0/24 #492

Open
gitisgreat2023 opened this issue Dec 1, 2023 · 9 comments

Comments

@gitisgreat2023
Copy link

Monthly timestamps at 23:59 are displayed one month into the future. E.g. 2023 Sept 30th 23:59 is shown as Oct 2023.
Nov 30 23:59 is actually even shown as 0/2024 (not 12/2023, or at least off by one as 12/2023).

Somehow the whole time axis of the bar chart is buggy. I'm willing to fix the code, can give someone a head-start where the issue might be hidden, in which lines?

@SilasMueller
Copy link

Isnt this exactly the same you already posted? #475

@Norb1204
Copy link

Norb1204 commented Dec 1, 2023

Some hints:

  • I assume that the month starts with 0 instead of 1. This is probably the shift of one month.
  • It looks like that the calculation is based on 30 days per month. But months have days between 28 and 31.
  • This concerns not only months, also days that are shifted by 1 into the future (Probably also hours).

I believe that the general problem is that everything starts from 0 instead of 1 and the calculation of the months is always with 30 days.

@gitisgreat2023
Copy link
Author

Isnt this exactly the same you already posted? #475

no, I see a shift by 2 months here, not by one day.
November is for example displayed as 0/2024 (january)

@jh2k19
Copy link

jh2k19 commented May 19, 2024

The same problem here.
image
image

@jh2k19
Copy link

jh2k19 commented May 27, 2024

Sorry, I missed something there. Under Appearance there is a parameter X-Label-offset. This is the desired solution for me.
image

@gitisgreat2023
Copy link
Author

gitisgreat2023 commented May 27, 2024

Yeah that works. Though the mouse over still shows the wrong value. I have a new issue, two months are counted as one (February 2024).

@Norb1204
Copy link

A comment exists in the code "ChartModel.js", maybe someone can take a look at it and assist the developer a bit.

ChartModel

@jh2k19
Copy link

jh2k19 commented Jun 17, 2024

Hier ein Codeschnipsel den ich mal mit ChatGPT ertellet habe.
Ich weis aber nicht wie man den Einbait bzw. möchte hier am Code auf Git nichts falsch oder kaputt machen.

function daysInMonth(year, month) {
return new Date(year, month + 1, 0).getDate();
}

function calculateMonths(start, end) {
start = new Date(start);
end = new Date(end);

// Set to the beginning of the next month
end.setDate(1);
end.setHours(0);
end.setMinutes(0);
end.setSeconds(0);
end.setMilliseconds(0);
end.setMonth(end.getMonth() + 1);

let totalDays = 0;
let current = new Date(start.getTime());

while (current < end) {
    totalDays += daysInMonth(current.getFullYear(), current.getMonth());
    current.setMonth(current.getMonth() + 1);
}

let months = totalDays / 30;
return Math.round(months);

}

let start = new Date('2023-01-15').getTime(); // Beispiel-Startdatum
let end = new Date('2023-06-17').getTime(); // Beispiel-Enddatum

Erklärung des Codes:

daysInMonth(year, month) Funktion:

Diese Funktion gibt die tatsächliche Anzahl der Tage im angegebenen Monat zurück.
Sie verwendet den Trick, dass der Tag 0 des nächsten Monats der letzte Tag des aktuellen Monats ist.
calculateMonths(start, end) Funktion:

Diese Funktion berechnet die Anzahl der Monate zwischen start und end.
Der end Zeitpunkt wird auf den Beginn des nächsten Monats gesetzt.
Eine Schleife summiert die Anzahl der Tage in jedem Monat zwischen start und end.
Schließlich wird die Gesamtanzahl der Tage durch 30 geteilt, um die Anzahl der Monate zu berechnen, und das Ergebnis wird gerundet.
Dieser Ansatz berücksichtigt die tatsächliche Anzahl der Tage in jedem Monat und liefert eine genauere Berechnung.

let option = {};
option.count = calculateMonths(start, end);

console.log(option.count);

@Erwin40
Copy link

Erwin40 commented Jul 25, 2024

Sorry, I missed something there. Under Appearance there is a parameter X-Label-offset. This is the desired solution for me. image

Das ist ziemlicher Unsinn.
Das mag für Statistiken passen, die nur Monate als Wert haben, aber nicht für solche mit Tagen oder Urzeiten.
Da stimmt das Datum der Cursor Position nicht mehr mit dem im ToolTip angezeigten Datum überein :-(

grafik

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants