【问题标题】:pass Json object to google charts API将 Json 对象传递给谷歌图表 API
【发布时间】:2017-12-21 21:57:11
【问题描述】:
$(document).ready(function () {
$.ajax({
  type: 'GET',
  url: 'api/v1/readings',
  data: { get_param: 'readings' },
  dataType: 'json',
  success: function (data) {
       google.charts.load('current', {'packages':['corechart']});
       google.charts.setOnLoadCallback(drawChart);

       var readings = data.readings;



       function drawChart() {
         var chartdata = new google.visualization.DataTable();
           chartdata.addColumn('datetime', 'Time of Day');
           chartdata.addColumn('number', 'Glucose Value');
           chartdata.addRows([

             readings.forEach(function(item){
               let date = new Date(item.time);
               { [[`Date(${date.getYear()}, ${date.getMonth()}, ${date.getDate()})`], item.glucose_value]}
             })
           ]);

所以我试图将 JSON readings 中的日期字符串传递给谷歌图表 api,但我收到了 every row must be a null or array 的错误。

文档https://developers.google.com/chart/interactive/docs/datesandtimes#datestring 声明日期必须在引号中传递,那么我如何将我的Date 变量传递到字符串中以便将其解析为图表的日期时间对象?

【问题讨论】:

    标签: javascript ruby-on-rails json


    【解决方案1】:

    您将其作为对象传递:{}

    取出对象表示法,作为[[]]传递

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-23
      • 1970-01-01
      • 2017-04-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-01
      • 1970-01-01
      相关资源
      最近更新 更多