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

Feature Request: Localization of datetime #35

Closed
arkhenstone opened this issue Aug 14, 2018 · 5 comments
Closed

Feature Request: Localization of datetime #35

arkhenstone opened this issue Aug 14, 2018 · 5 comments
Labels
feature-request New feature or request

Comments

@arkhenstone
Copy link

There is some UI elements in apexcharts that are locked into english, like date format. Even if we can configure the way it's displayed, we can't have the config format the date in another language.

Just let the datetimeFormatter object takes the localization token.

Vanilla JS takes it like with a simple string like 'FR-fr' as parameter of toLocaleString()

MDN toLocaleString function documentation

@junedchhipa junedchhipa added the feature-request New feature or request label Aug 14, 2018
@junedchhipa
Copy link
Contributor

@arkhenstone Tested the date.toLocaleString() function and it looks like it returns the full date and time in this format 20/12/2012 03:00:00
This will result in more work for me to split the string and re-calculate label count and determine if years/months/day should be displayed.

I suggest, using the options.xaxis.labels.formatter function to override dates/times to suit your needs.
Here is an example using moment.js in formatter
https://codepen.io/apexcharts/pen/MBRrbX

and here is an example of how you can use .toLocaleString() in options.xaxis.labels.formatter function
https://codepen.io/apexcharts/pen/oMOdBv

@Carniatto
Copy link

Carniatto commented Aug 30, 2018

I checked your example and the date passed to the formatter is already formatted before. If you put two different years in the series it gets all wrong.

I think it should pass the raw value to the formatter

@junedchhipa
Copy link
Contributor

Ah! right.
I will check that.

@junedchhipa
Copy link
Contributor

junedchhipa commented Sep 8, 2018

I have provided an additional parameter in options.xaxis.labels.formatter as a timestamp which you can use to format dates as per your needs.

Example:

xaxis: {
  tickAmount: 6,
  labels: {
    formatter: function(val, timestamp) {
      return moment(timestamp).format("DD MMM YYYY");
    }
  }
},

Note that here - tickAmount will respond to the value you provide.
Read more - https://apexcharts.com/docs/options/xaxis/#formatter

With this update, I have also provided localization options which you can set in options.chart.locales
Read more - https://apexcharts.com/docs/options/chart/locales/

So, from now on: you will be able to set your preferred language strings in some elements.

Cheers

@junedchhipa
Copy link
Contributor

Can we close this if I have not missed anything regarding localization?

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

No branches or pull requests

3 participants