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

How can I use a date in the rows attribute? #334

Open
simasch opened this issue Nov 16, 2023 · 4 comments
Open

How can I use a date in the rows attribute? #334

simasch opened this issue Nov 16, 2023 · 4 comments

Comments

@simasch
Copy link

simasch commented Nov 16, 2023

I'm trying to use a timeline chart where I have to pass dates.

But do I pass dates to the rows attribute?

I tried:

rows='[["Jan", "2019-06-21T08:12:00.000Z"]]'

But get:

Error: Type mismatch. Value 2019-06-21T08:12:00.000Z does not match type date in column index 1

@rslawik
Copy link
Contributor

rslawik commented Nov 18, 2023

This is not possible without custom deserialization to parse the attribute. Currently, the default JSON.parse is used (https://lit.dev/docs/components/properties/#conversion-type), so strings are not parsed as Dates.

My recommendation is to pass rows as a property from JS with the value that uses Date objects.

@simasch
Copy link
Author

simasch commented Nov 19, 2023

That looks like a huge limitation because I cannot use the web component without using JavaScript.

@rslawik
Copy link
Contributor

rslawik commented Nov 19, 2023

Looking through the docs, I found https://developers.google.com/chart/interactive/docs/datesandtimes#dates-and-times-using-the-date-string-representation which documents a custom serialization for Dates. It is used when DataTable is created, but not when rows are added (like here).

We can use data attribute instead of cols and rows to get Dates deserialized:

<google-chart
    type="timeline"
    data='[[{"label": "Label", "type": "string"},{"label": "Start", "type": "date"},{"label": "End", "type": "date"}],["a", {"v": "Date(2023, 8, 5)"}, {"v": "Date(2023, 8, 30)"}]]'>
</google-chart>

That looks like a huge limitation because I cannot use the web component without using JavaScript.

Is the input for the chart static? I would expect most applications to generate the input dynamically, in which case JavaScript is already involved.

@simasch
Copy link
Author

simasch commented Nov 21, 2023

Yes, the input is static generated in a Java app. With data it works fine.

Thanks @rslawik

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

No branches or pull requests

2 participants