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

access to google.visualization.DateFormat with 1.1.0? #142

Open
raphaelsavina opened this issue Aug 3, 2016 · 3 comments
Open

access to google.visualization.DateFormat with 1.1.0? #142

raphaelsavina opened this issue Aug 3, 2016 · 3 comments
Assignees

Comments

@raphaelsavina
Copy link

Since I've updated to 1.1.0 I can't access DateFormat. I might need to use the new google-chart-loader but the docs, readme and release notes didn't give any indication of that.

My dates are as EPOC (1470240006293) (as var d in this example), I was using:

var dateFormatter = new google.visualization.DateFormat({
   pattern: "d/MM H:mm"
});
var theDate = [dateFormatter.formatValue(new Date(parseInt(d)))];

It throws:
my-charts.html:102 Uncaught TypeError: Cannot read property 'DateFormat' of undefined

...maybe I've removed something else while I was updating.

@wesalvaro wesalvaro self-assigned this Aug 5, 2016
@wesalvaro
Copy link
Member

wesalvaro commented Aug 5, 2016

You are getting that error because the library has not been loaded yet. I'm kind of glad you're getting that error, now as it reveals a race condition that was very hard to debug with the previous version. My team suffered a huge setback because of it.

Currently, a few objects (DataTable, DataView, Query) are exposed, but there are others that may be desired.

Do you have an idea for a nice way to expose the other types?

Currently, you can do this:

document.createElement('google-chart-loader').dataTable().then(dataTable => {
  let formatter = new google.visualization.DateFormat({
    pattern: "d/MM H:mm"
  });
  let now = new Date();
  console.log(formatter.formatValue(now));
});

You could also access the (currently private) promise for the corechart package:

document.createElement('google-chart-loader')._corePackage.then(viz => {
  let formatter = new viz.DateFormat({
    pattern: "d/MM H:mm"
  });
  let now = new Date();
  console.log(formatter.formatValue(now));
});

Neither of these situations are ideal, but I'm not sure what a good way to do it is.

@raphaelsavina
Copy link
Author

raphaelsavina commented Aug 5, 2016

That worked (1st one), thanks!

Maybe having flag(s) like googleChart.drawn for the useful objects... would be a nicer solution.

@wesalvaro
Copy link
Member

The problem with using drawn is that you probably need the formatter to create the data set. drawn isn't true until the chart data is loaded and the data is actually drawn.

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

No branches or pull requests

2 participants