Quinn-Curtis Forums
Quinn-Curtis Forums
Home | Profile | Register | Active Topics | Members | Search | FAQ
 All Forums
 Tools for Java
 QCSPCChart SPC for Java
 pushJSONChartCreate is not defined

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkInsert EmailInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
   

T O P I C    R E V I E W
aletenti Posted - 06 Apr 2017 : 04:06:51
Hi everyone. I'm a newbie and i'm developing a web app in c# and asp.net that shows charts dinamically. I managed to pass JSON string from c# code to the asp.net one using the ViewState and I want to create my chart using "pushJSONChartCreate". to do this i have to import the nocache.js library like this:
<script language="javascript" type="text/javascript" 
src="QCSPCChartGWTWar/qcspcchartgwt/qcspcchartgwt.nocache.js"></script>

(the src is correct, because the folder "QCSPCChartGWTWar" is in the main web folder).

this is the asp.net code:
<script language="javascript" type="text/javascript">
    window.onload = function setData() {
        console.log("loaded");
        var stringa = document.getElementById('stringa_json').value;
        alert(stringa);
        pushJSONChartCreate(JSON.stringify(stringa));
    }
</script>


this is the c# code:
String JSONfinale = generaStringa(stringaJSON);
ViewState.Add("json_code", JSONfinale);
Page.ClientScript.RegisterHiddenField("stringa_json", 
ViewState["json_code"].ToString());


the asp.net code shows in an alert the JSON string passed succesfully with the ViewState, so the application enter in this block of code, but in browser console I see this error:
Uncaught ReferenceError: pushJSONChartCreate is not defined
at setData (Alessio.aspx:18)
setData @ Alessio.aspx:18


Anyone can help me?

Thank you,
Alessio
4   L A T E S T    R E P L I E S    (Newest First)
aletenti Posted - 12 Apr 2017 : 03:18:08
Thank you so much! It works
quinncurtis Posted - 07 Apr 2017 : 09:09:34
No, you need one or the other. Your timing approach is perfectly valid, though of indeterminate reliability since the exact delay needed for a given web page/browser loading is not known. The defineChartUsingJSON will always work, no matter the timing.

If you want to use the pushJSONChartCreate for the initial load of the chart, then before you call it, test for the functions existence (typeof pushJSONChartCreate != "undefined")at the time of the call using code similar to below. If it isn't present, delay 50 ms and then try again. The code below times out after 20 tries (1 sec). This runs asynchronously with the actual loading of the library and should catch the instant you can call pushJSONChartCreate .


if (typeof pushJSONChartCreate != "undefined") {
    pushJSONChartCreate(spcData);
} else {
    var timeoutlimitcountmax = 20;
    var timeoutinterval = 50; // milliseconds
    var timeoutcount = 0;

    var intervaltimer = setInterval(function () {
      if (typeof pushJSONChartCreate != "undefined") {
        pushJSONChartCreate(spcData);
        clearInterval(intervaltimer);
      } else {
        timeoutcount++;
        if (timeoutcount > timeoutlimitcountmax)
            clearInterval(intervaltimer);
      }
    }, timeoutinterval);
 }


aletenti Posted - 07 Apr 2017 : 03:57:09
Thanks for your reply. I temporarily set a timeout and it works. I see that the chart also appears without the defineChartUsingJSON() function. Is it essential?

Piece of my ASP.NET code

<script language="javascript" type="text/javascript">
    setTimeout(function () {
        console.log("loaded");
        var stringa = document.getElementById('stringa_json').value;
        console.log(stringa);
        pushJSONChartCreate(stringa);
    }, 2000);
</script>
quinncurtis Posted - 06 Apr 2017 : 09:20:21
Assuming everything else is correct, I suspect that it is a timing issue. Everything tends to load asynchronously in a web page. So when the onload event occurs, the qcspcchartgwt.nocache.js has not yet finished loading, (it is quite large), and therefore the pushJSONChartCreate function is not present at that instant. It will be present in N milliseconds though, after the qcspcchartgwt.nocache.js has finished loading.

So get the call to pushJSONChartCreate out of the onload event.

Instead, define your chart by placing it in a defineChartUsingJSON function, as seen in our example SPCSimple.htm, and most all of our other examples. For your code it would looks something like:

function defineChartUsingJSON( )
{
var stringa = JSON.stringify(document.getElementById('stringa_json').value);
return stringa ;
}



Once loaded, our library looks for the existence of this function in the parent HTML page and if present, calls it, where it expects a valid JSON SPC Chart setup string to be returned. It is impossible to tell if your JSON script is valid, but that will result in a different error message.

For future events on the same web page you can use the pushJSONChartCreate function, because now you know the SPC chart library has been loaded.

Quinn-Curtis Forums © 2000-2018 Quinn-Curtis, Inc. Go To Top Of Page
Powered By: Snitz Forums 2000 Version 3.4.07