Dies ist die Webseite, wo ich org zeigen möchte. Graph. DataArray-Variablenspeicher [[{v:"John",f:"junior Employee"}, ,"Junior Employee"]]
Wert. und ich habe Daten durch Ajax ist ["[{v:"John",f:"Junior Employee"}, ,"Junior Employee"]"]
.Wie korrigiere ich diesen Code, um Google Org anzuzeigen? Diagramm richtig?
Ich habe diesen Fehler:
SyntaxError: Unexpected token v in JSON at position 3
Code:
<html>
<head>
<title>Case Graphs</title>
<script src="./js/my/jquery-2.1.1.min.js"></script>
<!--<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> -->
<script type="text/javascript" src="loader.js"></script>
<script type="text/javascript">
$("document").ready(function(){
$("#getGraph").click(function(){
$.ajax({
url:"./DataPHP3.php",
method:"POST",
dataType:'json',
success:function(data){
console.log(data);
var length=data.length;
google.charts.load('current', {packages:["orgchart"]});
google.charts.setOnLoadCallback(drawChart);
var dataArray=[];
for(var k=0;k<length;k++)
{
if(k==0)
{
dataArray+="["+data[k];
}
else
{
dataArray+=","+data[k];
}
}
dataArray+="]";
function drawChart() {
console.log(dataArray);
var data = new google.visualization.DataTable();
data.addColumn('string', 'Name');
data.addColumn('string', 'Manager');
data.addColumn('string', 'ToolTip');
// For each orgchart box, provide the name, manager, and tooltip to show.
data.addRows(
$.parseJSON(dataArray)
// [[{v:"John",f:"junior Employee"}, ,"Junior Employee"]]
);
// Create the chart.
var chart = new google.visualization.OrgChart(document.getElementById('chart_div'));
// Draw the chart, setting the allowHtml option to true for the tooltips.
chart.draw(data, {allowHtml:true});
}
},
});
});
});
</script>``
</head>
<body>
<input type="button" id="getGraph" value="Show Graph">
<div id="chart_div" style="width: 900px; height: 400px"></div>
</body>
</html>
This is webpage,where i want to show org. graph. dataArray variable store [[{v:"John",f:"junior Employee"}, ,"Junior Employee"]]
value. and i got data through ajax is ["[{v:"John",f:"Junior Employee"}, ,"Junior Employee"]"].
I GOT THIS ERROR:
SyntaxError: Unexpected token v in JSON at position 3
Verwendung dieser Methode data.setCell() -Daten in Tabelle zu schreiben, anstatt gesamte Format des Kopierens !!! –
Formatierung verbessert. – Florian