miloschuman / yii2-highcharts

Highcharts widget for Yii 2 Framework
http://www.yiiframework.com/extension/yii2-highcharts-widget/
MIT License
166 stars 63 forks source link

Failed to add the sub tasks dynamically to gantt chart #88

Open bogere opened 3 years ago

bogere commented 3 years ago

Problem The gannt chart is able to display well when using the tasks. However when you try to add the subtasks dynamically to the series object, it generates the error below. This error does not show if you are using static data, it only shows when you load the subtasks dynamically. Error Uncaught TypeError: Cannot read property 'push' of undefined at gantt.src.js:1119 at Array.forEach (<anonymous>) at gantt.src.js:1118 at Array.forEach (<anonymous>) at getListOfParents (gantt.src.js:1115) at Object.getTree (gantt.src.js:1195) at getTreeGridFromData (gantt.src.js:3607) at gantt.src.js:3688 at Array.forEach (<anonymous>) at Chart.onBeforeRender (gantt.src.js:3631) I have tried both options of using the GanttChart::widget([]) and also utilising the javascript library directly. Highcharts.ganttChart

Steps to reproduce

<?php
use yii\bootstrap4\Html;
use yii\helpers\Url;
//use miloschuman\highcharts\GanttChart; // iam not using this method for now.
use miloschuman\highcharts\HighchartsAsset;
use yii\web\JsExpression;
use yii\web\View;

HighchartsAsset::register($this)->withScripts([ 'modules/gantt','modules/exporting']);
?>
<div class = "card">
    <div id = "chart-container"></div>
</div>

<?php
$script = <<< JS
$('document').ready(function($){ 
  var chartData = [] ; // load it from the server
      // THE CHART
                Highcharts.ganttChart('chart-container', {
                        title: {
                           text: 'Highcharts Gantt With Subtasks'
                        },
                        series: [{
                            name: 'Project 1',
                            data: chartData
                            }]
                        });
                }
}

sample chartData I am loading this data from the server. so please use the dynamic data. JSON data.

[
   {
  end: 1622278839000
  id: 34
  name: "Soccer week"
  seriesIndex: 0
  start: 1620464439000   
},
{
end: 1622192439000
id: 35
name: "Preparing the sports tracks"
seriesIndex: 0
start: 1621501239000
}
]