Jesper
Jesper

Reputation: 1086

chartjs with local dates

The ticks in my xAxis in my current chart are in the correct format, but the wrong language. For example: "22 July 21:00"

I would like them to be localized like "22 Heinäkuuta 21:00", but the "locale property" doesn't seem to change anything. Am i doing it wrong?

var config = { // my chart config
    type: 'line',
    data: { datasets: [] }, 
    options: { 
        parsing: false,
        normalized: true,
        animation: false,
        locale: "fi-FI", // my locale

        scales: {
            xAxis: {
                type: 'time',

                time: {
                    source: 'auto',
                    minUnit: 'hour',

                    displayFormats: {
                        minute: "dd MMMM HH:mm",
                        hour: "dd MMMM HH:mm",
                        day: "dd MMMM",
                        week: "dd MMMM",
                        month: "MMMM",
                        quarter: 'MMMM yyyy',
                        year: "yyyy",
                    }
                }
            },
        }, 
    }
}

I've read all of the document's i could find. but i can't make sense of this locale documentation

Upvotes: 1

Views: 672

Answers (1)

Jesper
Jesper

Reputation: 1086

I needed to give the locale to my date library which is Luxon for me:

luxon.Settings.defaultLocale = "fi";

Moment does it in a similar way but i haven't tested this:

moment.locale("fi");

here is some more information on it

Upvotes: 1

Related Questions