pChart 2.x forum
http://wiki.pchart.net/forum/

AJAX problems
http://wiki.pchart.net/forum/viewtopic.php?f=1&t=2342
Page 1 of 1

Author:  andreselsuave [ Thu Feb 02, 2012 4:27 pm ]
Post subject:  AJAX problems

Hello there.

I am developing a program in php that accepts some parameters from the client and generates a graph based on them.

How do I do this asynchronously? Maybe this is more an ajax/JS issue but I don't know how to return more than one parameter from the server to the client asynchronously. The idea would be to return text results to some edit buttons and a graph to a <img src> attribute.

Code:
function bbcalc(temperature,lmin,lmax)
{
   
if (temperature==null || lmax==null || lmin==null || temperature=="" || lmax=="" || lmin=="" ||
isNaN(parseFloat(temperature))==1 || isNaN(parseFloat(lmin))==1  || isNaN(parseFloat(lmax))==1 ){
    document.getElementById("error").innerHTML="Por favor, introduzca todos los parĂ¡metros de entrada";
    return 0;
}   
else if ( parseFloat(lmin) >= parseFloat(lmax)){
    document.getElementById("error").innerHTML="El limite inferior tiene que ser menor que el superior";
    return 0;
}
else
    {
   document.getElementById("error").innerHTML="";
    }
    if (document.getElementById("unitselect").selectedIndex==0){ //nm selected. We need to convert units
    lmin=1e7/lmin;
    lmax=1e7/lmax;
} //else, units in cm-1. no need to convert units


if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  xmlhttp.onreadystatechange=function()
  {
    if (xmlhttp.readyState==4 && xmlhttp.status==200)
      {
      document.getElementById("result").value=xmlhttp.responseText;
      }
  }
  xmlhttp.open("GET","bb.php?temp="+temperature+"&lmin="+lmin+"&lmax="+lmax,true);
  xmlhttp.send();

  document.getElementById('grafica').src='mypic.php';

}


Code:
<?php
include("class/pDraw.class.php");
include("class/pImage.class.php");
include("class/pData.class.php");

/* Create your dataset object */
$myData = new pData();

/* Add data in your dataset */
$myData->addPoints(array(VOID,3,4,3,5));

/* Create a pChart object and associate your dataset */
$myPicture = new pImage(700,230,$myData);

/* Choose a nice font */
$myPicture->setFontProperties(array("FontName"=>"fonts/Forgotte.ttf","FontSize"=>11));

/* Define the boundaries of the graph area */
$myPicture->setGraphArea(60,40,670,190);

/* Draw the scale, keep everything automatic */
$myPicture->drawScale();

/* Draw the scale, keep everything automatic */
$myPicture->drawSplineChart();

/* Build the PNG file and send it to the web browser */
$myPicture->stroke();

?>

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/