Chartjs-In chart.js how can I change the x axis on my line \chart from January-December to October-September? Basically, fiscal year instead of calendar year

0👍

The solution was to get the fiscal years correct:

                $.each(data, function (i, row) {
                    CumulativeDayTotal = parseInt(row[yValueKey]) + parseInt(CumulativeDayTotal);
                    // MLP 12/22/16: If not a cumulative report then set dates to be in the same year (2016)
                    // so chartjs will stack lines instead of spreading across multiple years. This was Austin
                    // Martin's code. I assume he chose 2016 because it is a leap year and will include
                    // February 29 in case the user selects a date range that includes Feb 29.
                    formattedDate = row["DATE_F"];
                    if (nsData.myChartFormat !== "cumulative") {
                        formattedDate = moment(formattedDate).year(2016);
                    }
                    // MLP 12/22/16: If fiscal chart, set October 1 through December 31 to 2015
                    // so char will show October through September instead of January through December.

Here:

                    if (nsData.myChartFormat === "fiscal") {
                        if (moment(formattedDate).format("YYYY/MM/DD") >= "2016/10/01") {
                            formattedDate = moment(formattedDate).year(2015);
                        }
                    }




                    // MLP 12/13/16: format date to UTC MM/DD/YYYY using momentJS because the JavsScript
                    // Date function converts dates to the local time zone.
                    formattedDate = formatDateUtc(formattedDate);
                    yAxis.push("{ y: " + CumulativeDayTotal + ", x: '" + formattedDate + "'}");
                });

Leave a comment