question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Change axes months language

See original GitHub issue

I’m submitting a … (check one with “x”)

  • bug report - search github for a similar issue or PR before submitting
  • feature request
  • support request - use StackOverflow (add the ngx-charts tag) or the gitter chat for support questions

Current behavior

Hi, I’m working with ngx-charts, I get a JSON with a structure similar to this one:

[
  {
    "name": "Réunion",
    "series": [
      {
        "value": 4500,
        "name": "2016-09-17T09:08:09.631Z"
      },
      {
        "value": 6193,
        "name": "2016-09-19T15:58:09.930Z"
      },
      {
        "value": 4003,
        "name": "2016-09-19T07:59:57.198Z"
      },
      {
        "value": 6137,
        "name": "2016-09-17T16:12:09.567Z"
      },
      {
        "value": 4178,
        "name": "2016-09-13T12:24:55.620Z"
      }
    ]
  },
  {
    "name": "Réunion",
    "series": [
      {
        "value": 4905,
        "name": "2016-09-17T09:08:09.631Z"
      },
      {
        "value": 4014,
        "name": "2016-09-19T15:58:09.930Z"
      },
      {
        "value": 6364,
        "name": "2016-09-19T07:59:57.198Z"
      },
      {
        "value": 5178,
        "name": "2016-09-17T16:12:09.567Z"
      },
      {
        "value": 5943,
        "name": "2016-09-13T12:24:55.620Z"
      }
    ]
  },
  {
    "name": "Chile",
    "series": [
      {
        "value": 5591,
        "name": "2016-09-17T09:08:09.631Z"
      },
      {
        "value": 3054,
        "name": "2016-09-19T15:58:09.930Z"
      },
      {
        "value": 3881,
        "name": "2016-09-19T07:59:57.198Z"
      },
      {
        "value": 3528,
        "name": "2016-09-17T16:12:09.567Z"
      },
      {
        "value": 2314,
        "name": "2016-09-13T12:24:55.620Z"
      }
    ]
  },
  {
    "name": "Suriname",
    "series": [
      {
        "value": 5628,
        "name": "2016-09-17T09:08:09.631Z"
      },
      {
        "value": 6187,
        "name": "2016-09-19T15:58:09.930Z"
      },
      {
        "value": 5970,
        "name": "2016-09-19T07:59:57.198Z"
      },
      {
        "value": 4305,
        "name": "2016-09-17T16:12:09.567Z"
      },
      {
        "value": 2944,
        "name": "2016-09-13T12:24:55.620Z"
      }
    ]
  },
  {
    "name": "Senegal",
    "series": [
      {
        "value": 3874,
        "name": "2016-09-17T09:08:09.631Z"
      },
      {
        "value": 6686,
        "name": "2016-09-19T15:58:09.930Z"
      },
      {
        "value": 4061,
        "name": "2016-09-19T07:59:57.198Z"
      },
      {
        "value": 6735,
        "name": "2016-09-17T16:12:09.567Z"
      },
      {
        "value": 4148,
        "name": "2016-09-13T12:24:55.620Z"
      }
    ]
  }
]

to make the transformation I use the following code:

this.data = this.multi.map(group => {
          group.series = group.series.map(dataItem => {
            // dataItem.name = moment(dataItem.name).format('llll');
            dataItem.name = new Date(dataItem.name);
 
            return dataItem;

          });

          return group;


        });

My problem is that the lower bar of the X axis appear in English and I would like to change the language. How could I do this without losing the timeline?

img

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:6
  • Comments:5

github_iconTop GitHub Comments

1reaction
dlehmanncommented, Aug 19, 2020

You can use ngx-translate to translate your x-axis ticks.

In your component.html:

<ngx-charts-line-chart
    [xAxisTickFormatting]="translate"
</ngx-charts-line-chart>

In your component.ts:

// ...

constructor(
    private translateService: TranslateService
){}

// ...

translate = (value) => {
    return this.translateService.instant(value);
}

// ...
0reactions
Mikilll94commented, Aug 13, 2020

Unfortunately the language is harcoded in app.component.ts in this line:

const monthName = new Intl.DateTimeFormat('en-us', { month: 'short' });
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Change Line Chart X-asix Month Language
How to Change Line Chart X-asix Month Language · 1. Go to query-editor · 2. Select New Source and from there Blank Query...
Read more >
How do I change the 'months' language displayed on the date ...
I am using Chart JS to plot data and on the date axis (x-axis) shows '20 Dec ...
Read more >
Change language of shown months on the X-Axis
Hello Community,. in my datasource I have 2 fields, which are called as "Year" and "Calendar Month". Both fields are combined by integer ......
Read more >
Change axis labels in a chart in Office - Microsoft Support
The chart uses text from your source data for axis labels. To change the label, you can change the text in the source...
Read more >
8.17 Using Dates on an Axis | R Graphics Cookbook, 2nd edition
Months and days have different names in different languages (the examples here are generated with a US locale). You can change the locale...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found