Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a locale for Chart.js date labels?

I have a Vue component, which renderes different charts using Chart.js. And everything is ok, but I can't set a locale for date labels on X axe.

I've tried to define moment locale at the top of script section of my vue-component, but it brought no results.

<script>
    import * as moment from 'moment';
    import 'moment/locale/ru';
    moment.locale('ru');

    console.log(moment.locale()); // it shows needle language: 'ru'!

    import Chart from 'chart.js';

    export default { ... this.chart = new Chart(this.context, config); ... };
</script>

^ but... after this try I see on X axe: 'Jul 2013', 'Aug 2013', but not 'Июл 2013', 'Авг 2013'.

Who have faced with such problem and how you have solved it? Somebody, help, please 🤞🏻

like image 530
s. v. Avatar asked Sep 14 '25 08:09

s. v.


1 Answers

I've solved it.

You should use this adapter https://github.com/chartjs/chartjs-adapter-date-fns to translate months on the chart.

like image 181
s. v. Avatar answered Sep 15 '25 20:09

s. v.