javascript - How to get values using function argument in js in codeigniter -
in ajax getting values values
variable, values not getting items variable. reason that?
what doing wrong? inside onload
function, values
variable alerted undefined. can me please? thanks.
the code using follows:
<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>
there problem in implementation. take @ sample.
<script type="text/javascript" language="javascript"> // step 1 // on window load data using ajax window.onload = function () { getajaxdata(); } // step 2 // after getting data, call chart function , pass data function getajaxdata() { var values; $.ajax({ cache : false, type : "get", url : 'chartvalues', format:'json', success: function(values) { onloaddoc(values); } }); } // step 3 // process chart using passed data function onloaddoc(values) { var chart1; 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------------ var items = values; chart1.setdatasource(items); chart1.getview3d().setenabled(true); var chartdiv = document.getelementbyid('chartdiv1'); chart1.create(chartdiv); } </script>
Comments
Post a Comment