Не удается прочитать свойство 'valueOf' нулевой диаграммы Google Gannt - PullRequest
0 голосов
/ 08 февраля 2020

Привет, я пытался использовать диаграммы Google Gannt, и я отображаю это сообщение вместо диаграммы:

Cannot read property 'valueOf' of null×

Вот мой код:

Это скрипт, который строит диаграмму {% для проекта в проектах%} google.charts.load ('current', {'packages': ['gantt']}); google.charts.setOnLoadCallback (drawChart);

    function drawChart() {
    arr = []
    data_arr = []
    var pk = "{{project.sales_project_id}}"
    var endpoint2 = '/api/gantt/data/'
    $.ajax({
      type: "GET",
      url: endpoint2,
      success: function(data){
        for (i = 0; i < data.timeline.length; i++) {
          if (data.timeline[i][2] == pk) {
                data.timeline[i][0].toString()
                data.timeline[i][1].toString()
                data.timeline[i][2].toString()
                arr.push(data.timeline[i])
              }
        }
        },

            });
      console.log(arr)

      var data = new google.visualization.DataTable();
      data.addColumn('string', 'Task ID');
      data.addColumn('string', 'Task Name');
      data.addColumn('string', 'POC');
      data.addColumn('date', 'Start Date');
      data.addColumn('date', 'End Date');
      data.addColumn('number', 'Duration');
      data.addColumn('number', 'Percent Complete');
      data.addColumn('string', 'Dependencies');

      data.addRows(data_arr);



      var options = {
        height: 400,
        gantt: {
          trackHeight: 30
        }
      };

      var chart = new google.visualization.Gantt(document.getElementById('chart_div'));
      chart.draw(data, options);
    }
  </script>
  {%endfor%}
</head>
{% endblock content %}

Это данные моей конечной точки API:

    {
    "timeline": [
        [
            1,
            1,
            2,
            "2020-02-08",
            "2020-02-01",
            null,
            20,
            null
        ],
        [
            2,
            2,
            2,
            "2020-02-08",
            "2020-05-08",
            null,
            80,
            null
        ],
        [
            3,
            3,
            2,
            "2020-02-08",
            "2020-09-08",
            null,
            80,
            null
        ]
    ]
}

согласно google

вот как они форматируют данные:

  data.addRows([
    ['2014Spring', 'Spring 2014', 'spring',
     new Date(2014, 2, 22), new Date(2014, 5, 20), null, 100, null],
    ['2014Summer', 'Summer 2014', 'summer',
     new Date(2014, 5, 21), new Date(2014, 8, 20), null, 100, null]
  ]);

и вот мой формат данных, как видно из моей консоли:

    []
0: (8) [1, 1, 2, "2020-02-08", "2020-02-01", null, 20, null]
1: (8) [2, 2, 2, "2020-02-08", "2020-05-08", null, 80, null]
2: (8) [3, 3, 2, "2020-02-08", "2020-09-08", null, 80, null]
length: 3
__proto__: Array(0)

Я не знаю, в чем заключается ошибка кто-нибудь может дать мне какое-то руководство здесь?

...