Giter Club home page Giter Club logo

Comments (7)

yann510 avatar yann510 commented on May 13, 2024 7

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?

from ngx-charts.

marjan-georgiev avatar marjan-georgiev commented on May 13, 2024 4

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

from ngx-charts.

yann510 avatar yann510 commented on May 13, 2024

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 ?

from ngx-charts.

marjan-georgiev avatar marjan-georgiev commented on May 13, 2024

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.

from ngx-charts.

vforvasquez avatar vforvasquez commented on May 13, 2024

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?

from ngx-charts.

Moulde avatar Moulde commented on May 13, 2024

@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.

from ngx-charts.

Moulde avatar Moulde commented on May 13, 2024

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

from ngx-charts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.