Ngx-charts: Date values not having a friendly display (as in the demo)

Created on 4 Oct 2016  路  7Comments  路  Source: swimlane/ngx-charts

Currently trying to reproduce the area-chart from the demo and with the same options and data passed to the table I'm getting this for the dates:
image

I'm also wondering if the epoch is supported in this current version?

Question Working as Intended

Most helpful comment

How about having an option for the x axis where you could specify it's type?
For example:
[xAxisType]="dateEpoch"

The xAxisType could of course be an enum specifying the possible types.
I think this would solve all the points you've mentioned and it remove the need from the user to parse the dates.
What do you think?

All 7 comments

Did you copy the data from the sidebar in the demo page? The dates there get converted to string for the JSON representation. In order to get a time scale on the line and area charts, you need to use date objects. If you use strings, you get an ordinal scale.

There's an argument here for detecting whether the string is a representation of a date and converting it internally, but I believe this should be handled outside the charts.

Take a look at this plunkr for an example. I convert the strings into date objects in the constructor in app.ts: https://plnkr.co/edit/HOXr8K?p=preview

There's an argument here for detecting whether the string is a representation of a date and converting it internally, but I believe this should be handled outside the charts.

@marjan-georgiev can you explain why you believe this should be handle outside the charts? I believe many charts do rely on dates/time ?

Sure. I think it is easier to do some minor wrangling and give the chart precise, formatted data, than have the chart guess whether you want it to treat your strings as dates or actual strings.

  • What if you wanted those values to be treated as strings?
  • What if you had the dates in a different format - should we try to parse any possible date format out there?
  • What if you didn't have strings, but integers - do we try to parse them as dates too?

These are all decisions that the user needs to make, not the chart.

I do think we should make assumptions when applicable in order to cut on configuration, but not here.

How about having an option for the x axis where you could specify it's type?
For example:
[xAxisType]="dateEpoch"

The xAxisType could of course be an enum specifying the possible types.
I think this would solve all the points you've mentioned and it remove the need from the user to parse the dates.
What do you think?

Just a heads up if you use the code from the constructor in the plunkr you get a "Type 'Date' is not assignable to type 'string'." warning. Is this from an older version of TS?

@yann510 I also think this is something the chart should handle. But i also agree with @marjan-georgiev that the chart should not try to guess what the data is, so i like your suggestion about specifying xAxisType.

@marjan-georgiev Parsing integers as a dates is pretty normal in javascript no? (Im thinking specifically about unix epoch).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

stephanrauh picture stephanrauh  路  4Comments

DZDomi picture DZDomi  路  4Comments

amcdnl picture amcdnl  路  4Comments

workfel picture workfel  路  3Comments

lokeshdaiya picture lokeshdaiya  路  3Comments