json - Reploting a JQplot chart using ajax -



json - Reploting a JQplot chart using ajax -

i have been trying solve in different ways, haven't create work expected, sense isn't big deal (i hope so) experience , skills ajax , jquery kind of limited that's why appealing expertise!

i working on chart similar 1 here http://www.jqplot.com/tests/data-renderers.php. in case json file generated depending on value user choses select box. using 2 files , ajax calls accomplish this:

-annualb.html file select box located , chart should displayed.

-index.php file query database made (using value obtained selectbox in annualb.html) , json array generated.

in annualb.html utilize method retrieve value selectbox , send index.php, generates json data. based on json info chart has created in annualb... here problem comes. function generate chart working fine , phone call send select value , homecoming json working (have checked firebug), know missing (but don't know yet) because don't manage pass json info function generates chart.

my codes in annualb.html goes (abbreviating irrelevant info ...):

function generate chart (is working ok if json info passed)

function creategraph() { $(document).ready(function(){ var ajaxdatarenderer = function(url, plot) { var ret = null; $.ajax({ async: false, url: url, datatype:'json', success: function(data) { ret = data; } }); homecoming ret; }; $.jqplot.config.enableplugins = true; var jsonurl = "./index.php"; var plotdata = ajaxdatarenderer(jsonurl); var series = ... plot1 = $.jqplot('chart1', series,{...}}

ajax call (probably mistake/omission is)

function loadgraph(int) { if (window.xmlhttprequest) {xmlhttp=new xmlhttprequest();} else {xmlhttp=new activexobject("microsoft.xmlhttp");} xmlhttp.open("get","index.php?tasel="+int,true); xmlhttp.send(); xmlhttp.onreadystatechange=function() { creategraph(int) } }

select box

<select name="tasel" size="1" onchange="loadgraph(this.value)"> <option value="">select accounts type:</option> <option value="3">tuloslaskelma</option> <option value="2">tasevastattava</option> <option value="1">tasevastaava</option> </select>

the related code in index.php goes (is working ok when value of select box (tasel) passed)):

$tasel = $_request['tasel']; if ($tasel == ...2) {...} . . . echo "[",$selite, ",";// these 2 variables create json array echo $finaljson, "]";

thanks in advance patience , help!

i realized reply question simpler expecting. instead of making whole function loadgraph(int) ajax call, needed phone call tasel value ?tasel="+int in function generate chart (which doing ajax call):

function creategraph() { $(document).ready(function(){ var ajaxdatarenderer = function(url, plot) { var ret = null; $.ajax({ async: false, url: url, datatype:'json', success: function(data) { ret = data; } }); homecoming ret; }; $.jqplot.config.enableplugins = true; var jsonurl = "./index.php?tasel="+int; var plotdata = ajaxdatarenderer(jsonurl); var series = ... plot1 = $.jqplot('chart1', series,{...} }

ajax json jqplot

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -