Ich möchte ein Google Graph auf einer WordPress-Seite anzeigen.
Ich habe gelernt Hier dass WordPress mit Javascript in Ordnung zu sein scheint.
Also habe ich eine Seite mit einem grundlegenden Code erstellt (es ist das Beispiel von GCharts). Meine Seite sieht so aus:
<!--Load the AJAX API-->
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
// Load the Visualization API and the piechart package.
google.load('visualization', '1.0', {'packages':['corechart']});
// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawChart);
// Callback that creates and populates a data table,
// instantiates the pie chart, passes in the data and
// draws it.
function drawChart() {
// Create the data table.
var data = new google.visualization.DataTable();
data.addColumn('string', 'Topping');
data.addColumn('number', 'Slices');
data.addRows([
['Mushrooms', 3],
['Onions', 1],
['Olives', 1],
['Zucchini', 1],
['Pepperoni', 2]
]);
// Set chart options
var options = {'title':'How Much Pizza I Ate Last Night',
'width':400,
'height':300};
// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
<div id="chart_div"></div>
Leider wird auf meiner Seite nichts angezeigt.
Hat jemand eine Ahnung was los ist?
Danke
BEARBEITEN :
Ich habe herausgefunden, dass da etwas mit dem < ist[CDATA[ tag added by WordPress. in my code, this tag may be broken by a "]" Charakter, und das würde das Problem verursachen.
Hier die Firebug-Info:
syntax error
google.setOnLoadCallback(drawChart);</p>
?page_id=22 (line 88, col 43)
das
ist in meinem Code nicht vorhanden !!
Mir ist aufgefallen, dass sich der Code ändert, wenn ich auf meiner Seite auf “Aktualisieren” klicke:
<script type="text/javascript">// <![CDATA[
// Load the Visualization API and the piechart package.
google.load('visualization', '1.0', {'packages':['corechart']});
// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawChart);
// Callback that creates and populates a data table,
// instantiates the pie chart, passes in the data and
// draws it.
function drawChart() {
// Create the data table.
var data = new google.visualization.DataTable();
data.addColumn('string', 'Topping');
data.addColumn('number', 'Slices');
data.addRows([
['Mushrooms', 3],
['Onions', 1],
['Olives', 1],
['Zucchini', 1],
['Pepperoni', 2]
]);
// Set chart options
var options = {'title':'How Much Pizza I Ate Last Night',
'width':400,
'height':300};
// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
// ]]></script>