question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Google-chart polymer demo and web API are Okay, but ...

See original GitHub issue

It would be really nice to have a “true” Polymer example of the google-chart element.

Specific examples of how to structure data, row, column, options using data-binding would be nice.

How to make it so that charts will size and resize appropriately depending on the container and with different viewports and devices, would also be nice.

For example,

<link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="../bower_components/google-chart/google-chart.html">


<link rel="import" href="shared-styles.html">

<dom-module id="my-gauge">
  <template>
    <style include="shared-styles">
      :host {
        display: block;
      }
    </style>

    <div class="wrapper">
      <google-chart
          id="gauge"
          type="gauge"
          data='{{data}}'
          options='{{options}}'
          on-google-chart-ready='chartLoaded'>
      </google-chart>
    </div>

  </template>

  <script>
    Polymer({
      is: 'my-gauge',

      properties: {
        data: {
          type: Array,
          notify: true
        },

        options: {
          type: Object,
          notify: true
        }
      },

      behaviors: [
        Polymer.AppNetworkStatusBehavior,
        Polymer.IronResizableBehavior,
      ],

      listeners: {
        'iron-resize': '_onIronResize'
      },

      ready: function() {
        console.log('my-gauge is ready')
      },

      attached: function() {
        this.async(this.notifyResize, 1);

      },

      _onIronResize: function() {
      },

      chartLoaded: function() {
        console.log('google gauge chart is loaded')
      }
    });
  </script>
</dom-module>

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
DMTSourcecommented, Feb 2, 2017

To get resizing of google-chart object to work from inside a Polymer template, I set the css of my chart div to 100% and used the IronResizeableBehavior to trigger on resize actions. One main issue was the use of “redraw” on the google-chart vs other incorrect examples online. The charts now smoothly resize to fit their responsive containers.

<style>
#marketchart {
        height: 200px;
        width: 100%;
 }
</style>

<google-chart
        id="marketchart"
        type="line"
        options='{"vAxis": {"minValue" : 0, "maxValue": 10},
                  "chartArea": {"width": "90%"},
                  "legend": {"position": "none"},
                  "selectionMode": "multiple"}'
        cols='[{"label": "Month", "type": "string"},{"label": "Days", "type": "number"}, {"label": "Days", "type": "number"}]'
        rows='[["Jan", 31, 22],["Feb", 28, 19],["Mar", 31, 17],["Apr", 30, 25],["May", 31, 29],["Jun", 30, 22]]'>
</google-chart>

<script>
    Polymer({
      is: 'my-dashboard',

      behaviors: [
        Polymer.IronResizableBehavior
      ],

      listeners: {
        'iron-resize': '_onIronResize'
      },

      attached: function() {
        this.async(this.notifyResize, 1);
      },

      get parent() {
        if (this.parentNode.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
          return this.parentNode.host;
        }
        return this.parentNode;
      },

      _onIronResize: function() {
        // Ensure every chart is redrawn on resize for full responsiveness
        this.$.marketchart.redraw(); 
      }

    });
  </script>
0reactions
esd100commented, Mar 28, 2017

@wesalvaro it looks like you are making some big changes, some of which look very interesting.

You mention in the draft that loading will be done through iron-ajax for example. I think providing one complete example of that would be nice and very useful for people that aren’t very familiar with web development.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Addy Osmani on Twitter: "&lt;google-chart&gt;: Google Charts ...
I was chatting with someone at EmpireJS about doing charts as web components. glad someone had the time to do them!
Read more >
Google Visualization API Reference | Charts
This page lists the objects exposed by the Google Visualization API, ... cells is safe, and changes are immediately propagated to the DataView...
Read more >
How to render <google-chart> web component in Polymer
I can't get a <google-chart> element to render on my page. I used Yeoman's Polymer generator to scaffold a Polymer project.
Read more >
Lit
Every Lit component is a native web component, with the superpower of interoperability. Web components work anywhere you use HTML, with any framework...
Read more >
What Polymer and Angular tell us about the future success of ...
Polymer provides a “low enough” level API that gives web ... but Yehuda does a great job covering the details at a high...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found