I'm having an issue in my Ajax code where the values are not being stored in the items variable even though they are properly fetched and assigned to the values variable. Can anyone spot what I might be doing wrong?
Specifically, within the onload function, the values variable is showing up as undefined when alerted. Any assistance would be greatly appreciated. Thank you!
The code snippet in question is shown below:
<script type="text/javascript" language="javascript">
var values;
$.ajax({
cache : false,
type: "GET",
url: 'chartvalues',
format:'json',
success: function(response)
{
//alert(response);
values = response;
//alert (values);
}
});
window.onload = function () {
onLoadDoc();
}
var chart1;
function onLoadDoc() {
chart1 = new cfx.Chart();chart1.getAnimations().getLoad().setEnabled(true);
var axisY = chart1.getAxisY();
axisY.setMin(0);
axisY.setMax(30);
//----Assign data fields--------
var fields = chart1.getDataSourceSettings().getFields();
var field1 = new cfx.FieldMap();
field1.setName("Value");
field1.setUsage(cfx.FieldUsage.Value);
fields.add(field1);
var field2 = new cfx.FieldMap();
field2.setName("Date");
field2.setUsage(cfx.FieldUsage.XValue);
fields.add(field2);
chart1.setGallery(cfx.Gallery.Bar);
//----Set Sample Data------------
alert (values);
var items = values;
//alert (items);
chart1.setDataSource(items);
chart1.getView3D().setEnabled(true);
var chartDiv = document.getElementById('ChartDiv1');
chart1.create(chartDiv);
}
</script>