Hi there,
You don't need generate generateChartData function. You're not generating the data but rather loading it.
You will definitely need loadJSON function, though. Put it anywhere in the JavaScript block. Then add it's call within AmCharts.ready() enclosure.
The final code might look something like this:
AmCharts.loadJSON = function(url) {
// create the request
if (window.XMLHttpRequest) {
// IE7+, Firefox, Chrome, Opera, Safari
var request = new XMLHttpRequest();
} else {
// code for IE6, IE5
var request = new ActiveXObject('Microsoft.XMLHTTP');
}
// load it
// the last "false" parameter ensures that our code will wait before the
// data is loaded
request.open('GET', url, false);
request.send();
// parse adn return the output
return eval(request.responseText);
};
var chartData = AmCharts.loadJSON('data.php');
var %CHART% = AmCharts.makeChart("%CHART%", {
type: "stock",
"theme": "none",
pathToImages: "http://www.amcharts.com/lib/3/images/",
dataSets: [{
title: "Cloud Index",
fieldMappings: [{
fromField: "value",
toField: "value"
}, {
fromField: "volume",
toField: "volume"
}],
dataProvider: chartData,
categoryField: "date"
},
],
panels: [{
showCategoryAxis: true,
title: "Value",
percentHeight: 70,
stockGraphs: [{
id: "g1",
valueField: "value",
comparable: true,
compareField: "value",
balloonText: "<a href="http://codex.wordpress.org/title">title</a>:<b><a href="http://codex.wordpress.org/value">value</a></b>",
compareGraphBalloonText: "<a href="http://codex.wordpress.org/title">title</a>:<b><a href="http://codex.wordpress.org/value">value</a></b>"
}],
stockLegend: {
periodValueTextComparing: "[[percents.value.close]]%",
periodValueTextRegular: "[[value.close]]"
}
}
],
chartScrollbarSettings: {
graph: "g1"
},
chartCursorSettings: {
valueBalloonsEnabled: true
},
periodSelector: {
position: "left",
periods: [{
period: "MM",
selected: true,
count: 1,
label: "1 month"
}, {
period: "YYYY",
count: 1,
label: "1 year"
}, {
period: "YTD",
label: "YTD"
}, {
period: "MAX",
label: "MAX"
}]
},
dataSetSelector: {
position: "left"
}
});