GoogleChart JSON












1















Trying to create a google GANTT Chart using JSON Data via PHP and AJAX in a local host. I am getting the following error. I am unable to understand the error and how it's loaded.:



Uncaught TypeError: Cannot read property '3' of undefined
at gvjs_Tba (jsapi_compiled_default_module.js:132)
at new gvjs_R (jsapi_compiled_default_module.js:131)
at Object.<anonymous> (ganttchart.html:23)
at c (jquery.min.js:4)
at Object.fireWith [as resolveWith] (jquery.min.js:4)
at k (jquery.min.js:6)
at XMLHttpRequest.r (jquery.min.js:6)
gvjs_Tba @ jsapi_compiled_default_module.js:132
gvjs_R @ jsapi_compiled_default_module.js:131
(anonymous) @ ganttchart.html:23
c @ jquery.min.js:4
fireWith @ jquery.min.js:4
k @ jquery.min.js:6
r @ jquery.min.js:6
XMLHttpRequest.send (async)
send @ jquery.min.js:6
ajax @ jquery.min.js:6
drawChart @ ganttchart.html:18
Promise.then (async)
google.G.K.U.hl @ loader.js:231
(anonymous) @ ganttchart.html:11


My HTML DOC where I do an AJAX reference to the PHP page. I changed the AJAX call from the previous version to include done



  <html>
<head>
<!--Load the AJAX API-->
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">

google.charts.load('current', {'packages':['gantt']});

google.charts.setOnLoadCallback(drawChart);

function drawChart() {
$.ajax({
url: "getGanttData.php", // make this url point to the data file
dataType: "json"
}).done(function (jsonData) {
// Create our data table out of JSON data loaded from server.
var data = new google.visualization.DataTable(jsonData);

var options = {
//explorer: {axis: 'horizontal'}
height: 275,
gantt: {
defaultStartDateMillis: new Date(2019, 1, 1)
}
};

// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.Gantt(document.getElementById('chart_div'));
chart.draw(data, options);
});
}
</script>
</head>

<body>

<div id="intro">
<h1>Supervisor's Dashbaord</h1>
</div>
<!--Div that will hold the pie chart-->
<div id="chart_div"></div>
</body>
</html>


PHP Script - This reads teh sample gantt details string and pulls the data: getGanttData.php



<?php 

$string = file_get_contents("sampleGanttData.json");
echo $string;

?>


My JSON Data: sampleGanttData.json



    {
"cols": [{"id": "ID", "label": "Task ID", "type": "string"},
{"id": "Name", "label": "Task Name", "type": "string"},
{"id": "Resource", "label": "Resource", "type": "string"},
{"id": "Start", "label": "Start Date", "type": "date"},
{"id": "End", "label": "End Date", "type": "date"},
{"id": "Duration", "label": "Duration", "type": "number"},
{"id": "Percent", "label": "Percentage complete", "type": "number"},
{"id": "Dependencies", "label": "Dependencies", "type": "string"}
],
"rows": [
{"c":[{"v": "T101"},
{"v": "WO:1 - create Design"},
{"v": "Engineer"},
{"v":"null"},
{"v":"null"},
{"v": 2.0},
{"v": 2.0},
{"v":"null"}
]},

[{"c":[{"v": "T102"},
{"v": "WO:1 - Gain Design Approval"},
{"v": "Engineer"},
{"v":"null"},
{"v":"null"},
{"v": 3.0},
{"v": 0.0},
{"v":"T101"}
]}
]
]
}









share|improve this question




















  • 1





    If an answer solved your problem, consider accepting the answer. Here's how meta.stackexchange.com/questions/5234/… then return here and do the same with the tick/checkmark till it turns green. This informs the community, a solution was found. Otherwise, others may think the question is still open and may want to post (more) answers. Welcome to Stack!

    – Jay Blanchard
    Nov 19 '18 at 21:54
















1















Trying to create a google GANTT Chart using JSON Data via PHP and AJAX in a local host. I am getting the following error. I am unable to understand the error and how it's loaded.:



Uncaught TypeError: Cannot read property '3' of undefined
at gvjs_Tba (jsapi_compiled_default_module.js:132)
at new gvjs_R (jsapi_compiled_default_module.js:131)
at Object.<anonymous> (ganttchart.html:23)
at c (jquery.min.js:4)
at Object.fireWith [as resolveWith] (jquery.min.js:4)
at k (jquery.min.js:6)
at XMLHttpRequest.r (jquery.min.js:6)
gvjs_Tba @ jsapi_compiled_default_module.js:132
gvjs_R @ jsapi_compiled_default_module.js:131
(anonymous) @ ganttchart.html:23
c @ jquery.min.js:4
fireWith @ jquery.min.js:4
k @ jquery.min.js:6
r @ jquery.min.js:6
XMLHttpRequest.send (async)
send @ jquery.min.js:6
ajax @ jquery.min.js:6
drawChart @ ganttchart.html:18
Promise.then (async)
google.G.K.U.hl @ loader.js:231
(anonymous) @ ganttchart.html:11


My HTML DOC where I do an AJAX reference to the PHP page. I changed the AJAX call from the previous version to include done



  <html>
<head>
<!--Load the AJAX API-->
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">

google.charts.load('current', {'packages':['gantt']});

google.charts.setOnLoadCallback(drawChart);

function drawChart() {
$.ajax({
url: "getGanttData.php", // make this url point to the data file
dataType: "json"
}).done(function (jsonData) {
// Create our data table out of JSON data loaded from server.
var data = new google.visualization.DataTable(jsonData);

var options = {
//explorer: {axis: 'horizontal'}
height: 275,
gantt: {
defaultStartDateMillis: new Date(2019, 1, 1)
}
};

// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.Gantt(document.getElementById('chart_div'));
chart.draw(data, options);
});
}
</script>
</head>

<body>

<div id="intro">
<h1>Supervisor's Dashbaord</h1>
</div>
<!--Div that will hold the pie chart-->
<div id="chart_div"></div>
</body>
</html>


PHP Script - This reads teh sample gantt details string and pulls the data: getGanttData.php



<?php 

$string = file_get_contents("sampleGanttData.json");
echo $string;

?>


My JSON Data: sampleGanttData.json



    {
"cols": [{"id": "ID", "label": "Task ID", "type": "string"},
{"id": "Name", "label": "Task Name", "type": "string"},
{"id": "Resource", "label": "Resource", "type": "string"},
{"id": "Start", "label": "Start Date", "type": "date"},
{"id": "End", "label": "End Date", "type": "date"},
{"id": "Duration", "label": "Duration", "type": "number"},
{"id": "Percent", "label": "Percentage complete", "type": "number"},
{"id": "Dependencies", "label": "Dependencies", "type": "string"}
],
"rows": [
{"c":[{"v": "T101"},
{"v": "WO:1 - create Design"},
{"v": "Engineer"},
{"v":"null"},
{"v":"null"},
{"v": 2.0},
{"v": 2.0},
{"v":"null"}
]},

[{"c":[{"v": "T102"},
{"v": "WO:1 - Gain Design Approval"},
{"v": "Engineer"},
{"v":"null"},
{"v":"null"},
{"v": 3.0},
{"v": 0.0},
{"v":"T101"}
]}
]
]
}









share|improve this question




















  • 1





    If an answer solved your problem, consider accepting the answer. Here's how meta.stackexchange.com/questions/5234/… then return here and do the same with the tick/checkmark till it turns green. This informs the community, a solution was found. Otherwise, others may think the question is still open and may want to post (more) answers. Welcome to Stack!

    – Jay Blanchard
    Nov 19 '18 at 21:54














1












1








1








Trying to create a google GANTT Chart using JSON Data via PHP and AJAX in a local host. I am getting the following error. I am unable to understand the error and how it's loaded.:



Uncaught TypeError: Cannot read property '3' of undefined
at gvjs_Tba (jsapi_compiled_default_module.js:132)
at new gvjs_R (jsapi_compiled_default_module.js:131)
at Object.<anonymous> (ganttchart.html:23)
at c (jquery.min.js:4)
at Object.fireWith [as resolveWith] (jquery.min.js:4)
at k (jquery.min.js:6)
at XMLHttpRequest.r (jquery.min.js:6)
gvjs_Tba @ jsapi_compiled_default_module.js:132
gvjs_R @ jsapi_compiled_default_module.js:131
(anonymous) @ ganttchart.html:23
c @ jquery.min.js:4
fireWith @ jquery.min.js:4
k @ jquery.min.js:6
r @ jquery.min.js:6
XMLHttpRequest.send (async)
send @ jquery.min.js:6
ajax @ jquery.min.js:6
drawChart @ ganttchart.html:18
Promise.then (async)
google.G.K.U.hl @ loader.js:231
(anonymous) @ ganttchart.html:11


My HTML DOC where I do an AJAX reference to the PHP page. I changed the AJAX call from the previous version to include done



  <html>
<head>
<!--Load the AJAX API-->
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">

google.charts.load('current', {'packages':['gantt']});

google.charts.setOnLoadCallback(drawChart);

function drawChart() {
$.ajax({
url: "getGanttData.php", // make this url point to the data file
dataType: "json"
}).done(function (jsonData) {
// Create our data table out of JSON data loaded from server.
var data = new google.visualization.DataTable(jsonData);

var options = {
//explorer: {axis: 'horizontal'}
height: 275,
gantt: {
defaultStartDateMillis: new Date(2019, 1, 1)
}
};

// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.Gantt(document.getElementById('chart_div'));
chart.draw(data, options);
});
}
</script>
</head>

<body>

<div id="intro">
<h1>Supervisor's Dashbaord</h1>
</div>
<!--Div that will hold the pie chart-->
<div id="chart_div"></div>
</body>
</html>


PHP Script - This reads teh sample gantt details string and pulls the data: getGanttData.php



<?php 

$string = file_get_contents("sampleGanttData.json");
echo $string;

?>


My JSON Data: sampleGanttData.json



    {
"cols": [{"id": "ID", "label": "Task ID", "type": "string"},
{"id": "Name", "label": "Task Name", "type": "string"},
{"id": "Resource", "label": "Resource", "type": "string"},
{"id": "Start", "label": "Start Date", "type": "date"},
{"id": "End", "label": "End Date", "type": "date"},
{"id": "Duration", "label": "Duration", "type": "number"},
{"id": "Percent", "label": "Percentage complete", "type": "number"},
{"id": "Dependencies", "label": "Dependencies", "type": "string"}
],
"rows": [
{"c":[{"v": "T101"},
{"v": "WO:1 - create Design"},
{"v": "Engineer"},
{"v":"null"},
{"v":"null"},
{"v": 2.0},
{"v": 2.0},
{"v":"null"}
]},

[{"c":[{"v": "T102"},
{"v": "WO:1 - Gain Design Approval"},
{"v": "Engineer"},
{"v":"null"},
{"v":"null"},
{"v": 3.0},
{"v": 0.0},
{"v":"T101"}
]}
]
]
}









share|improve this question
















Trying to create a google GANTT Chart using JSON Data via PHP and AJAX in a local host. I am getting the following error. I am unable to understand the error and how it's loaded.:



Uncaught TypeError: Cannot read property '3' of undefined
at gvjs_Tba (jsapi_compiled_default_module.js:132)
at new gvjs_R (jsapi_compiled_default_module.js:131)
at Object.<anonymous> (ganttchart.html:23)
at c (jquery.min.js:4)
at Object.fireWith [as resolveWith] (jquery.min.js:4)
at k (jquery.min.js:6)
at XMLHttpRequest.r (jquery.min.js:6)
gvjs_Tba @ jsapi_compiled_default_module.js:132
gvjs_R @ jsapi_compiled_default_module.js:131
(anonymous) @ ganttchart.html:23
c @ jquery.min.js:4
fireWith @ jquery.min.js:4
k @ jquery.min.js:6
r @ jquery.min.js:6
XMLHttpRequest.send (async)
send @ jquery.min.js:6
ajax @ jquery.min.js:6
drawChart @ ganttchart.html:18
Promise.then (async)
google.G.K.U.hl @ loader.js:231
(anonymous) @ ganttchart.html:11


My HTML DOC where I do an AJAX reference to the PHP page. I changed the AJAX call from the previous version to include done



  <html>
<head>
<!--Load the AJAX API-->
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">

google.charts.load('current', {'packages':['gantt']});

google.charts.setOnLoadCallback(drawChart);

function drawChart() {
$.ajax({
url: "getGanttData.php", // make this url point to the data file
dataType: "json"
}).done(function (jsonData) {
// Create our data table out of JSON data loaded from server.
var data = new google.visualization.DataTable(jsonData);

var options = {
//explorer: {axis: 'horizontal'}
height: 275,
gantt: {
defaultStartDateMillis: new Date(2019, 1, 1)
}
};

// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.Gantt(document.getElementById('chart_div'));
chart.draw(data, options);
});
}
</script>
</head>

<body>

<div id="intro">
<h1>Supervisor's Dashbaord</h1>
</div>
<!--Div that will hold the pie chart-->
<div id="chart_div"></div>
</body>
</html>


PHP Script - This reads teh sample gantt details string and pulls the data: getGanttData.php



<?php 

$string = file_get_contents("sampleGanttData.json");
echo $string;

?>


My JSON Data: sampleGanttData.json



    {
"cols": [{"id": "ID", "label": "Task ID", "type": "string"},
{"id": "Name", "label": "Task Name", "type": "string"},
{"id": "Resource", "label": "Resource", "type": "string"},
{"id": "Start", "label": "Start Date", "type": "date"},
{"id": "End", "label": "End Date", "type": "date"},
{"id": "Duration", "label": "Duration", "type": "number"},
{"id": "Percent", "label": "Percentage complete", "type": "number"},
{"id": "Dependencies", "label": "Dependencies", "type": "string"}
],
"rows": [
{"c":[{"v": "T101"},
{"v": "WO:1 - create Design"},
{"v": "Engineer"},
{"v":"null"},
{"v":"null"},
{"v": 2.0},
{"v": 2.0},
{"v":"null"}
]},

[{"c":[{"v": "T102"},
{"v": "WO:1 - Gain Design Approval"},
{"v": "Engineer"},
{"v":"null"},
{"v":"null"},
{"v": 3.0},
{"v": 0.0},
{"v":"T101"}
]}
]
]
}






javascript php ajax charts google-visualization






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 13 '18 at 0:09







Saachi

















asked Nov 19 '18 at 21:45









SaachiSaachi

133




133








  • 1





    If an answer solved your problem, consider accepting the answer. Here's how meta.stackexchange.com/questions/5234/… then return here and do the same with the tick/checkmark till it turns green. This informs the community, a solution was found. Otherwise, others may think the question is still open and may want to post (more) answers. Welcome to Stack!

    – Jay Blanchard
    Nov 19 '18 at 21:54














  • 1





    If an answer solved your problem, consider accepting the answer. Here's how meta.stackexchange.com/questions/5234/… then return here and do the same with the tick/checkmark till it turns green. This informs the community, a solution was found. Otherwise, others may think the question is still open and may want to post (more) answers. Welcome to Stack!

    – Jay Blanchard
    Nov 19 '18 at 21:54








1




1





If an answer solved your problem, consider accepting the answer. Here's how meta.stackexchange.com/questions/5234/… then return here and do the same with the tick/checkmark till it turns green. This informs the community, a solution was found. Otherwise, others may think the question is still open and may want to post (more) answers. Welcome to Stack!

– Jay Blanchard
Nov 19 '18 at 21:54





If an answer solved your problem, consider accepting the answer. Here's how meta.stackexchange.com/questions/5234/… then return here and do the same with the tick/checkmark till it turns green. This informs the community, a solution was found. Otherwise, others may think the question is still open and may want to post (more) answers. Welcome to Stack!

– Jay Blanchard
Nov 19 '18 at 21:54












1 Answer
1






active

oldest

votes


















1














yes, you will need to remove async: false to remove the deprecation warning



however, this will cause the rest of the chart code to run before the data has returned,

which will cause a different error



since the success function has also been deprecated,

move the rest of the code to the done promise to correct the issue,

as follows...



// Load the Visualization API and the piechart package.
google.charts.load('current', {'packages':['gantt']});

// Set a callback to run when the Google Visualization API is loaded.
google.charts.setOnLoadCallback(drawChart);

function toMilliseconds(hour) {
return hour * 60 * 1000 *60;
}

function drawChart() {
$.ajax({
url: "getGanttData.php", // make this url point to the data file
dataType: "json"
}).done(function (jsonData) {
// Create our data table out of JSON data loaded from server.
var data = new google.visualization.DataTable(jsonData);

var options = {
//explorer: {axis: 'horizontal'}
height: 275,
gantt: {
defaultStartDateMillis: new Date(2019, 1, 1)
}
};

// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.Gantt(document.getElementById('chart_div'));
chart.draw(data, options);
});
}


UPDATE



the json data is malformed. there is an extra opening and closing array brace in the second row, see comments.



{
"cols": [{"id": "ID", "label": "Task ID", "type": "string"},
{"id": "Name", "label": "Task Name", "type": "string"},
{"id": "Resource", "label": "Resource", "type": "string"},
{"id": "Start", "label": "Start Date", "type": "date"},
{"id": "End", "label": "End Date", "type": "date"},
{"id": "Duration", "label": "Duration", "type": "number"},
{"id": "Percent", "label": "Percentage complete", "type": "number"},
{"id": "Dependencies", "label": "Dependencies", "type": "string"}
],
"rows": [
{"c":[{"v": "T101"},
{"v": "WO:1 - create Design"},
{"v": "Engineer"},
{"v":"null"},
{"v":"null"},
{"v": 2.0},
{"v": 2.0},
{"v":"null"}
]},

// the following opening brace ([) should be removed
[{"c":[{"v": "T102"},
{"v": "WO:1 - Gain Design Approval"},
{"v": "Engineer"},
{"v":"null"},
{"v":"null"},
{"v": 3.0},
{"v": 0.0},
{"v":"T101"}
]}
] // <-- one of these closing braces should be removed
] // <-- one of these closing braces should be removed
}


also, if you're going to use a null value, it should not be in quotes.



{"v":"null"}  // <-- bad
{"v":null} // <-- good


however, at least one row should have a start and end date,

in the data sample supplied, both rows have null for the dates.



cleaning up the json should allow the chart to draw,

see following working snippet...






google.charts.load('current', {
packages: ['gantt']
}).then(function () {
var data = new google.visualization.DataTable({
"cols": [
{"id": "ID", "label": "Task ID", "type": "string"},
{"id": "Name", "label": "Task Name", "type": "string"},
{"id": "Resource", "label": "Resource", "type": "string"},
{"id": "Start", "label": "Start Date", "type": "date"},
{"id": "End", "label": "End Date", "type": "date"},
{"id": "Duration", "label": "Duration", "type": "number"},
{"id": "Percent", "label": "Percentage complete", "type": "number"},
{"id": "Dependencies", "label": "Dependencies", "type": "string"}
],
"rows": [
{"c":[
{"v": "T101"},
{"v": "WO:1 - create Design"},
{"v": "Engineer"},
{"v": null},
{"v": null},
{"v": 2.0},
{"v": 2.0},
{"v": null}
]},
{"c":[
{"v": "T102"},
{"v": "WO:1 - Gain Design Approval"},
{"v": "Engineer"},
{"v": "Date(2019, 1)"},
{"v": "Date(2019, 2)"},
{"v": 3.0},
{"v": 0.0},
{"v": "T101"}
]}
]
});

var options = {
height: 275,
gantt: {
defaultStartDateMillis: new Date(2019, 1, 1)
}
};

var chart = new google.visualization.Gantt(document.getElementById('chart_div'));
chart.draw(data, options);
});

<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>








share|improve this answer


























  • This does not fix the problem. :(

    – Saachi
    Dec 12 '18 at 22:08











  • will you please edit the question with the latest version of your code? do you receive any errors in the browser's console?

    – WhiteHat
    Dec 12 '18 at 22:20











  • First, I really appreciate the help. I get the error below: Uncaught TypeError: Cannot read property '3' of undefined at gvjs_Tba (jsapi_compiled_default_module.js:132) at new gvjs_R (jsapi_compiled_default_module.js:131) at Object.<anonymous> (ganttchart.html:23) at c (jquery.min.js:4) at Object.fireWith [as resolveWith] (jquery.min.js:4) at k (jquery.min.js:6) at XMLHttpRequest.r (jquery.min.js:6)

    – Saachi
    Dec 12 '18 at 23:51













  • see UPDATE above...

    – WhiteHat
    Dec 13 '18 at 13:23











  • Thank you so much!!! The code works

    – Saachi
    Dec 13 '18 at 21:46











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53383083%2fgooglechart-json%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














yes, you will need to remove async: false to remove the deprecation warning



however, this will cause the rest of the chart code to run before the data has returned,

which will cause a different error



since the success function has also been deprecated,

move the rest of the code to the done promise to correct the issue,

as follows...



// Load the Visualization API and the piechart package.
google.charts.load('current', {'packages':['gantt']});

// Set a callback to run when the Google Visualization API is loaded.
google.charts.setOnLoadCallback(drawChart);

function toMilliseconds(hour) {
return hour * 60 * 1000 *60;
}

function drawChart() {
$.ajax({
url: "getGanttData.php", // make this url point to the data file
dataType: "json"
}).done(function (jsonData) {
// Create our data table out of JSON data loaded from server.
var data = new google.visualization.DataTable(jsonData);

var options = {
//explorer: {axis: 'horizontal'}
height: 275,
gantt: {
defaultStartDateMillis: new Date(2019, 1, 1)
}
};

// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.Gantt(document.getElementById('chart_div'));
chart.draw(data, options);
});
}


UPDATE



the json data is malformed. there is an extra opening and closing array brace in the second row, see comments.



{
"cols": [{"id": "ID", "label": "Task ID", "type": "string"},
{"id": "Name", "label": "Task Name", "type": "string"},
{"id": "Resource", "label": "Resource", "type": "string"},
{"id": "Start", "label": "Start Date", "type": "date"},
{"id": "End", "label": "End Date", "type": "date"},
{"id": "Duration", "label": "Duration", "type": "number"},
{"id": "Percent", "label": "Percentage complete", "type": "number"},
{"id": "Dependencies", "label": "Dependencies", "type": "string"}
],
"rows": [
{"c":[{"v": "T101"},
{"v": "WO:1 - create Design"},
{"v": "Engineer"},
{"v":"null"},
{"v":"null"},
{"v": 2.0},
{"v": 2.0},
{"v":"null"}
]},

// the following opening brace ([) should be removed
[{"c":[{"v": "T102"},
{"v": "WO:1 - Gain Design Approval"},
{"v": "Engineer"},
{"v":"null"},
{"v":"null"},
{"v": 3.0},
{"v": 0.0},
{"v":"T101"}
]}
] // <-- one of these closing braces should be removed
] // <-- one of these closing braces should be removed
}


also, if you're going to use a null value, it should not be in quotes.



{"v":"null"}  // <-- bad
{"v":null} // <-- good


however, at least one row should have a start and end date,

in the data sample supplied, both rows have null for the dates.



cleaning up the json should allow the chart to draw,

see following working snippet...






google.charts.load('current', {
packages: ['gantt']
}).then(function () {
var data = new google.visualization.DataTable({
"cols": [
{"id": "ID", "label": "Task ID", "type": "string"},
{"id": "Name", "label": "Task Name", "type": "string"},
{"id": "Resource", "label": "Resource", "type": "string"},
{"id": "Start", "label": "Start Date", "type": "date"},
{"id": "End", "label": "End Date", "type": "date"},
{"id": "Duration", "label": "Duration", "type": "number"},
{"id": "Percent", "label": "Percentage complete", "type": "number"},
{"id": "Dependencies", "label": "Dependencies", "type": "string"}
],
"rows": [
{"c":[
{"v": "T101"},
{"v": "WO:1 - create Design"},
{"v": "Engineer"},
{"v": null},
{"v": null},
{"v": 2.0},
{"v": 2.0},
{"v": null}
]},
{"c":[
{"v": "T102"},
{"v": "WO:1 - Gain Design Approval"},
{"v": "Engineer"},
{"v": "Date(2019, 1)"},
{"v": "Date(2019, 2)"},
{"v": 3.0},
{"v": 0.0},
{"v": "T101"}
]}
]
});

var options = {
height: 275,
gantt: {
defaultStartDateMillis: new Date(2019, 1, 1)
}
};

var chart = new google.visualization.Gantt(document.getElementById('chart_div'));
chart.draw(data, options);
});

<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>








share|improve this answer


























  • This does not fix the problem. :(

    – Saachi
    Dec 12 '18 at 22:08











  • will you please edit the question with the latest version of your code? do you receive any errors in the browser's console?

    – WhiteHat
    Dec 12 '18 at 22:20











  • First, I really appreciate the help. I get the error below: Uncaught TypeError: Cannot read property '3' of undefined at gvjs_Tba (jsapi_compiled_default_module.js:132) at new gvjs_R (jsapi_compiled_default_module.js:131) at Object.<anonymous> (ganttchart.html:23) at c (jquery.min.js:4) at Object.fireWith [as resolveWith] (jquery.min.js:4) at k (jquery.min.js:6) at XMLHttpRequest.r (jquery.min.js:6)

    – Saachi
    Dec 12 '18 at 23:51













  • see UPDATE above...

    – WhiteHat
    Dec 13 '18 at 13:23











  • Thank you so much!!! The code works

    – Saachi
    Dec 13 '18 at 21:46
















1














yes, you will need to remove async: false to remove the deprecation warning



however, this will cause the rest of the chart code to run before the data has returned,

which will cause a different error



since the success function has also been deprecated,

move the rest of the code to the done promise to correct the issue,

as follows...



// Load the Visualization API and the piechart package.
google.charts.load('current', {'packages':['gantt']});

// Set a callback to run when the Google Visualization API is loaded.
google.charts.setOnLoadCallback(drawChart);

function toMilliseconds(hour) {
return hour * 60 * 1000 *60;
}

function drawChart() {
$.ajax({
url: "getGanttData.php", // make this url point to the data file
dataType: "json"
}).done(function (jsonData) {
// Create our data table out of JSON data loaded from server.
var data = new google.visualization.DataTable(jsonData);

var options = {
//explorer: {axis: 'horizontal'}
height: 275,
gantt: {
defaultStartDateMillis: new Date(2019, 1, 1)
}
};

// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.Gantt(document.getElementById('chart_div'));
chart.draw(data, options);
});
}


UPDATE



the json data is malformed. there is an extra opening and closing array brace in the second row, see comments.



{
"cols": [{"id": "ID", "label": "Task ID", "type": "string"},
{"id": "Name", "label": "Task Name", "type": "string"},
{"id": "Resource", "label": "Resource", "type": "string"},
{"id": "Start", "label": "Start Date", "type": "date"},
{"id": "End", "label": "End Date", "type": "date"},
{"id": "Duration", "label": "Duration", "type": "number"},
{"id": "Percent", "label": "Percentage complete", "type": "number"},
{"id": "Dependencies", "label": "Dependencies", "type": "string"}
],
"rows": [
{"c":[{"v": "T101"},
{"v": "WO:1 - create Design"},
{"v": "Engineer"},
{"v":"null"},
{"v":"null"},
{"v": 2.0},
{"v": 2.0},
{"v":"null"}
]},

// the following opening brace ([) should be removed
[{"c":[{"v": "T102"},
{"v": "WO:1 - Gain Design Approval"},
{"v": "Engineer"},
{"v":"null"},
{"v":"null"},
{"v": 3.0},
{"v": 0.0},
{"v":"T101"}
]}
] // <-- one of these closing braces should be removed
] // <-- one of these closing braces should be removed
}


also, if you're going to use a null value, it should not be in quotes.



{"v":"null"}  // <-- bad
{"v":null} // <-- good


however, at least one row should have a start and end date,

in the data sample supplied, both rows have null for the dates.



cleaning up the json should allow the chart to draw,

see following working snippet...






google.charts.load('current', {
packages: ['gantt']
}).then(function () {
var data = new google.visualization.DataTable({
"cols": [
{"id": "ID", "label": "Task ID", "type": "string"},
{"id": "Name", "label": "Task Name", "type": "string"},
{"id": "Resource", "label": "Resource", "type": "string"},
{"id": "Start", "label": "Start Date", "type": "date"},
{"id": "End", "label": "End Date", "type": "date"},
{"id": "Duration", "label": "Duration", "type": "number"},
{"id": "Percent", "label": "Percentage complete", "type": "number"},
{"id": "Dependencies", "label": "Dependencies", "type": "string"}
],
"rows": [
{"c":[
{"v": "T101"},
{"v": "WO:1 - create Design"},
{"v": "Engineer"},
{"v": null},
{"v": null},
{"v": 2.0},
{"v": 2.0},
{"v": null}
]},
{"c":[
{"v": "T102"},
{"v": "WO:1 - Gain Design Approval"},
{"v": "Engineer"},
{"v": "Date(2019, 1)"},
{"v": "Date(2019, 2)"},
{"v": 3.0},
{"v": 0.0},
{"v": "T101"}
]}
]
});

var options = {
height: 275,
gantt: {
defaultStartDateMillis: new Date(2019, 1, 1)
}
};

var chart = new google.visualization.Gantt(document.getElementById('chart_div'));
chart.draw(data, options);
});

<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>








share|improve this answer


























  • This does not fix the problem. :(

    – Saachi
    Dec 12 '18 at 22:08











  • will you please edit the question with the latest version of your code? do you receive any errors in the browser's console?

    – WhiteHat
    Dec 12 '18 at 22:20











  • First, I really appreciate the help. I get the error below: Uncaught TypeError: Cannot read property '3' of undefined at gvjs_Tba (jsapi_compiled_default_module.js:132) at new gvjs_R (jsapi_compiled_default_module.js:131) at Object.<anonymous> (ganttchart.html:23) at c (jquery.min.js:4) at Object.fireWith [as resolveWith] (jquery.min.js:4) at k (jquery.min.js:6) at XMLHttpRequest.r (jquery.min.js:6)

    – Saachi
    Dec 12 '18 at 23:51













  • see UPDATE above...

    – WhiteHat
    Dec 13 '18 at 13:23











  • Thank you so much!!! The code works

    – Saachi
    Dec 13 '18 at 21:46














1












1








1







yes, you will need to remove async: false to remove the deprecation warning



however, this will cause the rest of the chart code to run before the data has returned,

which will cause a different error



since the success function has also been deprecated,

move the rest of the code to the done promise to correct the issue,

as follows...



// Load the Visualization API and the piechart package.
google.charts.load('current', {'packages':['gantt']});

// Set a callback to run when the Google Visualization API is loaded.
google.charts.setOnLoadCallback(drawChart);

function toMilliseconds(hour) {
return hour * 60 * 1000 *60;
}

function drawChart() {
$.ajax({
url: "getGanttData.php", // make this url point to the data file
dataType: "json"
}).done(function (jsonData) {
// Create our data table out of JSON data loaded from server.
var data = new google.visualization.DataTable(jsonData);

var options = {
//explorer: {axis: 'horizontal'}
height: 275,
gantt: {
defaultStartDateMillis: new Date(2019, 1, 1)
}
};

// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.Gantt(document.getElementById('chart_div'));
chart.draw(data, options);
});
}


UPDATE



the json data is malformed. there is an extra opening and closing array brace in the second row, see comments.



{
"cols": [{"id": "ID", "label": "Task ID", "type": "string"},
{"id": "Name", "label": "Task Name", "type": "string"},
{"id": "Resource", "label": "Resource", "type": "string"},
{"id": "Start", "label": "Start Date", "type": "date"},
{"id": "End", "label": "End Date", "type": "date"},
{"id": "Duration", "label": "Duration", "type": "number"},
{"id": "Percent", "label": "Percentage complete", "type": "number"},
{"id": "Dependencies", "label": "Dependencies", "type": "string"}
],
"rows": [
{"c":[{"v": "T101"},
{"v": "WO:1 - create Design"},
{"v": "Engineer"},
{"v":"null"},
{"v":"null"},
{"v": 2.0},
{"v": 2.0},
{"v":"null"}
]},

// the following opening brace ([) should be removed
[{"c":[{"v": "T102"},
{"v": "WO:1 - Gain Design Approval"},
{"v": "Engineer"},
{"v":"null"},
{"v":"null"},
{"v": 3.0},
{"v": 0.0},
{"v":"T101"}
]}
] // <-- one of these closing braces should be removed
] // <-- one of these closing braces should be removed
}


also, if you're going to use a null value, it should not be in quotes.



{"v":"null"}  // <-- bad
{"v":null} // <-- good


however, at least one row should have a start and end date,

in the data sample supplied, both rows have null for the dates.



cleaning up the json should allow the chart to draw,

see following working snippet...






google.charts.load('current', {
packages: ['gantt']
}).then(function () {
var data = new google.visualization.DataTable({
"cols": [
{"id": "ID", "label": "Task ID", "type": "string"},
{"id": "Name", "label": "Task Name", "type": "string"},
{"id": "Resource", "label": "Resource", "type": "string"},
{"id": "Start", "label": "Start Date", "type": "date"},
{"id": "End", "label": "End Date", "type": "date"},
{"id": "Duration", "label": "Duration", "type": "number"},
{"id": "Percent", "label": "Percentage complete", "type": "number"},
{"id": "Dependencies", "label": "Dependencies", "type": "string"}
],
"rows": [
{"c":[
{"v": "T101"},
{"v": "WO:1 - create Design"},
{"v": "Engineer"},
{"v": null},
{"v": null},
{"v": 2.0},
{"v": 2.0},
{"v": null}
]},
{"c":[
{"v": "T102"},
{"v": "WO:1 - Gain Design Approval"},
{"v": "Engineer"},
{"v": "Date(2019, 1)"},
{"v": "Date(2019, 2)"},
{"v": 3.0},
{"v": 0.0},
{"v": "T101"}
]}
]
});

var options = {
height: 275,
gantt: {
defaultStartDateMillis: new Date(2019, 1, 1)
}
};

var chart = new google.visualization.Gantt(document.getElementById('chart_div'));
chart.draw(data, options);
});

<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>








share|improve this answer















yes, you will need to remove async: false to remove the deprecation warning



however, this will cause the rest of the chart code to run before the data has returned,

which will cause a different error



since the success function has also been deprecated,

move the rest of the code to the done promise to correct the issue,

as follows...



// Load the Visualization API and the piechart package.
google.charts.load('current', {'packages':['gantt']});

// Set a callback to run when the Google Visualization API is loaded.
google.charts.setOnLoadCallback(drawChart);

function toMilliseconds(hour) {
return hour * 60 * 1000 *60;
}

function drawChart() {
$.ajax({
url: "getGanttData.php", // make this url point to the data file
dataType: "json"
}).done(function (jsonData) {
// Create our data table out of JSON data loaded from server.
var data = new google.visualization.DataTable(jsonData);

var options = {
//explorer: {axis: 'horizontal'}
height: 275,
gantt: {
defaultStartDateMillis: new Date(2019, 1, 1)
}
};

// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.Gantt(document.getElementById('chart_div'));
chart.draw(data, options);
});
}


UPDATE



the json data is malformed. there is an extra opening and closing array brace in the second row, see comments.



{
"cols": [{"id": "ID", "label": "Task ID", "type": "string"},
{"id": "Name", "label": "Task Name", "type": "string"},
{"id": "Resource", "label": "Resource", "type": "string"},
{"id": "Start", "label": "Start Date", "type": "date"},
{"id": "End", "label": "End Date", "type": "date"},
{"id": "Duration", "label": "Duration", "type": "number"},
{"id": "Percent", "label": "Percentage complete", "type": "number"},
{"id": "Dependencies", "label": "Dependencies", "type": "string"}
],
"rows": [
{"c":[{"v": "T101"},
{"v": "WO:1 - create Design"},
{"v": "Engineer"},
{"v":"null"},
{"v":"null"},
{"v": 2.0},
{"v": 2.0},
{"v":"null"}
]},

// the following opening brace ([) should be removed
[{"c":[{"v": "T102"},
{"v": "WO:1 - Gain Design Approval"},
{"v": "Engineer"},
{"v":"null"},
{"v":"null"},
{"v": 3.0},
{"v": 0.0},
{"v":"T101"}
]}
] // <-- one of these closing braces should be removed
] // <-- one of these closing braces should be removed
}


also, if you're going to use a null value, it should not be in quotes.



{"v":"null"}  // <-- bad
{"v":null} // <-- good


however, at least one row should have a start and end date,

in the data sample supplied, both rows have null for the dates.



cleaning up the json should allow the chart to draw,

see following working snippet...






google.charts.load('current', {
packages: ['gantt']
}).then(function () {
var data = new google.visualization.DataTable({
"cols": [
{"id": "ID", "label": "Task ID", "type": "string"},
{"id": "Name", "label": "Task Name", "type": "string"},
{"id": "Resource", "label": "Resource", "type": "string"},
{"id": "Start", "label": "Start Date", "type": "date"},
{"id": "End", "label": "End Date", "type": "date"},
{"id": "Duration", "label": "Duration", "type": "number"},
{"id": "Percent", "label": "Percentage complete", "type": "number"},
{"id": "Dependencies", "label": "Dependencies", "type": "string"}
],
"rows": [
{"c":[
{"v": "T101"},
{"v": "WO:1 - create Design"},
{"v": "Engineer"},
{"v": null},
{"v": null},
{"v": 2.0},
{"v": 2.0},
{"v": null}
]},
{"c":[
{"v": "T102"},
{"v": "WO:1 - Gain Design Approval"},
{"v": "Engineer"},
{"v": "Date(2019, 1)"},
{"v": "Date(2019, 2)"},
{"v": 3.0},
{"v": 0.0},
{"v": "T101"}
]}
]
});

var options = {
height: 275,
gantt: {
defaultStartDateMillis: new Date(2019, 1, 1)
}
};

var chart = new google.visualization.Gantt(document.getElementById('chart_div'));
chart.draw(data, options);
});

<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>








google.charts.load('current', {
packages: ['gantt']
}).then(function () {
var data = new google.visualization.DataTable({
"cols": [
{"id": "ID", "label": "Task ID", "type": "string"},
{"id": "Name", "label": "Task Name", "type": "string"},
{"id": "Resource", "label": "Resource", "type": "string"},
{"id": "Start", "label": "Start Date", "type": "date"},
{"id": "End", "label": "End Date", "type": "date"},
{"id": "Duration", "label": "Duration", "type": "number"},
{"id": "Percent", "label": "Percentage complete", "type": "number"},
{"id": "Dependencies", "label": "Dependencies", "type": "string"}
],
"rows": [
{"c":[
{"v": "T101"},
{"v": "WO:1 - create Design"},
{"v": "Engineer"},
{"v": null},
{"v": null},
{"v": 2.0},
{"v": 2.0},
{"v": null}
]},
{"c":[
{"v": "T102"},
{"v": "WO:1 - Gain Design Approval"},
{"v": "Engineer"},
{"v": "Date(2019, 1)"},
{"v": "Date(2019, 2)"},
{"v": 3.0},
{"v": 0.0},
{"v": "T101"}
]}
]
});

var options = {
height: 275,
gantt: {
defaultStartDateMillis: new Date(2019, 1, 1)
}
};

var chart = new google.visualization.Gantt(document.getElementById('chart_div'));
chart.draw(data, options);
});

<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>





google.charts.load('current', {
packages: ['gantt']
}).then(function () {
var data = new google.visualization.DataTable({
"cols": [
{"id": "ID", "label": "Task ID", "type": "string"},
{"id": "Name", "label": "Task Name", "type": "string"},
{"id": "Resource", "label": "Resource", "type": "string"},
{"id": "Start", "label": "Start Date", "type": "date"},
{"id": "End", "label": "End Date", "type": "date"},
{"id": "Duration", "label": "Duration", "type": "number"},
{"id": "Percent", "label": "Percentage complete", "type": "number"},
{"id": "Dependencies", "label": "Dependencies", "type": "string"}
],
"rows": [
{"c":[
{"v": "T101"},
{"v": "WO:1 - create Design"},
{"v": "Engineer"},
{"v": null},
{"v": null},
{"v": 2.0},
{"v": 2.0},
{"v": null}
]},
{"c":[
{"v": "T102"},
{"v": "WO:1 - Gain Design Approval"},
{"v": "Engineer"},
{"v": "Date(2019, 1)"},
{"v": "Date(2019, 2)"},
{"v": 3.0},
{"v": 0.0},
{"v": "T101"}
]}
]
});

var options = {
height: 275,
gantt: {
defaultStartDateMillis: new Date(2019, 1, 1)
}
};

var chart = new google.visualization.Gantt(document.getElementById('chart_div'));
chart.draw(data, options);
});

<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>






share|improve this answer














share|improve this answer



share|improve this answer








edited Dec 13 '18 at 13:22

























answered Nov 19 '18 at 23:04









WhiteHatWhiteHat

35.9k61476




35.9k61476













  • This does not fix the problem. :(

    – Saachi
    Dec 12 '18 at 22:08











  • will you please edit the question with the latest version of your code? do you receive any errors in the browser's console?

    – WhiteHat
    Dec 12 '18 at 22:20











  • First, I really appreciate the help. I get the error below: Uncaught TypeError: Cannot read property '3' of undefined at gvjs_Tba (jsapi_compiled_default_module.js:132) at new gvjs_R (jsapi_compiled_default_module.js:131) at Object.<anonymous> (ganttchart.html:23) at c (jquery.min.js:4) at Object.fireWith [as resolveWith] (jquery.min.js:4) at k (jquery.min.js:6) at XMLHttpRequest.r (jquery.min.js:6)

    – Saachi
    Dec 12 '18 at 23:51













  • see UPDATE above...

    – WhiteHat
    Dec 13 '18 at 13:23











  • Thank you so much!!! The code works

    – Saachi
    Dec 13 '18 at 21:46



















  • This does not fix the problem. :(

    – Saachi
    Dec 12 '18 at 22:08











  • will you please edit the question with the latest version of your code? do you receive any errors in the browser's console?

    – WhiteHat
    Dec 12 '18 at 22:20











  • First, I really appreciate the help. I get the error below: Uncaught TypeError: Cannot read property '3' of undefined at gvjs_Tba (jsapi_compiled_default_module.js:132) at new gvjs_R (jsapi_compiled_default_module.js:131) at Object.<anonymous> (ganttchart.html:23) at c (jquery.min.js:4) at Object.fireWith [as resolveWith] (jquery.min.js:4) at k (jquery.min.js:6) at XMLHttpRequest.r (jquery.min.js:6)

    – Saachi
    Dec 12 '18 at 23:51













  • see UPDATE above...

    – WhiteHat
    Dec 13 '18 at 13:23











  • Thank you so much!!! The code works

    – Saachi
    Dec 13 '18 at 21:46

















This does not fix the problem. :(

– Saachi
Dec 12 '18 at 22:08





This does not fix the problem. :(

– Saachi
Dec 12 '18 at 22:08













will you please edit the question with the latest version of your code? do you receive any errors in the browser's console?

– WhiteHat
Dec 12 '18 at 22:20





will you please edit the question with the latest version of your code? do you receive any errors in the browser's console?

– WhiteHat
Dec 12 '18 at 22:20













First, I really appreciate the help. I get the error below: Uncaught TypeError: Cannot read property '3' of undefined at gvjs_Tba (jsapi_compiled_default_module.js:132) at new gvjs_R (jsapi_compiled_default_module.js:131) at Object.<anonymous> (ganttchart.html:23) at c (jquery.min.js:4) at Object.fireWith [as resolveWith] (jquery.min.js:4) at k (jquery.min.js:6) at XMLHttpRequest.r (jquery.min.js:6)

– Saachi
Dec 12 '18 at 23:51







First, I really appreciate the help. I get the error below: Uncaught TypeError: Cannot read property '3' of undefined at gvjs_Tba (jsapi_compiled_default_module.js:132) at new gvjs_R (jsapi_compiled_default_module.js:131) at Object.<anonymous> (ganttchart.html:23) at c (jquery.min.js:4) at Object.fireWith [as resolveWith] (jquery.min.js:4) at k (jquery.min.js:6) at XMLHttpRequest.r (jquery.min.js:6)

– Saachi
Dec 12 '18 at 23:51















see UPDATE above...

– WhiteHat
Dec 13 '18 at 13:23





see UPDATE above...

– WhiteHat
Dec 13 '18 at 13:23













Thank you so much!!! The code works

– Saachi
Dec 13 '18 at 21:46





Thank you so much!!! The code works

– Saachi
Dec 13 '18 at 21:46


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53383083%2fgooglechart-json%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

Npm cannot find a required file even through it is in the searched directory