You shoud put the php echoing in quotes and you also need to use + for concatenation in javascript:
<?php
$post_grandfather = "Dodo";
echo $post_grandfather;
?>
<html>
<head>
<script type="text/javascript">
var myvariable1 = '<?php echo addslashes($post_grandfather); ?>';
var a = '<?php echo addslashes($post_grandfather); ?>';
</script>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {packages:["orgchart"]});
google.charts.setOnLoadCallback(drawChart);
document.write(5 + 6);
function drawChart() {
var data = new google.visualization.DataTable();
var myvariable = '<?php echo addslashes($post_grandfather); ?>';
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([
[{'v':String(a), 'f': a + ' Mike<div style="color:red; font-style:italic">President</div>'},
'', 'The President'],
[{'v':'Jim', 'f':'Jim<div style="color:red; font-style:italic">Vice President</div>'},
'Mike', 'VP'],
['Alice', 'Mike', ''],
['Bob', 'Jim', 'Bob Sponge'],
['Carol', 'Bob', ''],
['Hamad','Alice', '']
]);
// 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>
<div id="chart_div"></div>
</body>
</html>
This should give:
Screenshot of the result
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…