javascript - Can I use iron-localstorage and iron-ajax with highcharts -
i have polymer element uses iron-ajax create highchart. incorporate iron-localstorage chart render data in ls unless ls empty in case call iron-ajax load data api?
my working element follows:
<dom-module id="sales-chart"> <template> <iron-ajax id="ajax" url="{{url}}" last-response="{{data}}"></iron-ajax> <div id="container" style="max-width: 600px; height: 360px;"></div> </template> <script> polymer({ is: "sales-chart", properties: { url: string, data: object }, observers: [ // these functions run once observed properties contain // other undefined. '_requestdata(url)', '_chartdata(data)' ], _requestdata: function(url) { // note: use `generaterequest()` instead of `auto` property // because `url` may not available when element // first created. this.$.ajax.generaterequest(); }, _chartdata: function (data) { $(this.$.container).highcharts({ chart: { type: 'spline', renderto: 'container' }, series: [{ data: (data.series) }] }); } }); </script> </dom-module>
something along these lines should work (did't test tough):
<dom-module id="sales-chart"> <template> <iron-ajax id="ajax" url="{{url}}" last-response="{{data}}"></iron-ajax> <div id="container" style="max-width: 600px; height: 360px;"></div> <iron-localstorage name="{{url}}" value="{{data}}" on-iron-localstorage-load-empty="_requestdata"> </iron-localstorage> </template> <script> polymer({ is: "sales-chart", properties: { url: string, data: object }, observers: [ // these functions run once observed properties contain // other undefined. '_chartdata(data)' ], _requestdata: function() { // note: use `generaterequest()` instead of `auto` property // because `url` may not available when element // first created. this.$.ajax.generaterequest(); }, _chartdata: function (data) { $(this.$.container).highcharts({ chart: { type: 'spline', renderto: 'container' }, series: [{ data: (data.series) }] }); } }); </script> </dom-module>
Comments
Post a Comment