timelinechart couldn't decode Array as JSON:

好久不见. 提交于 2019-12-13 03:56:11

问题


I'm getting the issue "couldn't decode Array as JSON: " for the below chart. Rest of the charts seem to work with this format but not this one.

 <google-chart type='timeline' options='{"title": "Timeline", 
                                  "legend" : {"position" : "bottom", "alignment": "start"}
                                }' cols='[{"label":"Question", "type":"string"},
                                          {"label":"Number", "type":"string"},
                                          {"label":"Start", "type":"date"}, 
                                          {"label":"End", "type":"date"} ]'
rows='[["Question1", "1", new Date(0,0,0,12,0,0), new Date(0,0,0,12,30,0)],
      ["Question2", "2", new Date(0,0,0,12,30,0), new Date(0,0,0,12,45,0)],
      ["Question3", "3",  new Date(0,0,0,12,45,0), new Date(0,0,0,1,0,0)],
      ["Question4", "4", new Date(0,0,0,1,0,0), new Date(0,0,0,1,12,0)],
      ["Question5", "5", new Date(0,0,0,1,12,0), new Date(0,0,0,1,30,0)]]'>
</google-chart>

回答1:


I little changed your code and its now working.

DEMO

<google-chart id="timeline" type='timeline' options='{"title": "Timeline"}'>

</google-chart>

and at the script:

ready() {
       super.ready();
       Polymer.RenderStatus.afterNextRender(this, () => {this.showChartTable(); })
}

showChartTable(){

      var chart = this.shadowRoot.querySelector('#timeline');
      document.createElement('google-chart-loader').dataTable([
          ['Question', 'Number', 'Start','End'],
        ["Question1", "1", new Date(1789, 3, 30), new Date(1800, 3, 30)],      ["Question2", "2", new Date(1800, 3, 30), new Date(1900, 3, 30)], ["Question3", "3",  new Date(1900, 3, 30), new Date(2000, 3, 30)], ["Question4", "4", new Date(2000, 3, 30), new Date(2018, 3, 30)], ["Question5", "5", new Date(2018, 3, 30),new Date(2020, 3, 30)]] ).then(function(dataTable) {
          chart.data = dataTable;
        });
}

Due to timeline logic, you should define a valid time line. Your dates gives error.

EDIT: no need to keep this chart inside connectedCallback. just move on own named functions as: showChartTable (I changed)



来源:https://stackoverflow.com/questions/49783933/timelinechart-couldnt-decode-array-as-json

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!