1

Actually I am trying to do a graph chart for all reports for that am using jQChart plugins. I have done the graph report by PHP but my head need that report with animation so I go to jQChart but I don't know how to pass the assoc array values to Ajax.

$results = mysql_query("SELECT vaccum_value,date FROM vaccum_details where serial_number='10P1005'");
$data1=array();
while ($row = mysql_fetch_array($results)) 
{
    $data1[$row['date']]=$row['vaccum_value'];
}  

$data = Array ( "28-Sep-2012" => 31.6, "04-Oct-2012" => 0.99, "03-Oct-2012" => -3 ); 

but I need to pass this result to Ajax and then convert to like this below:

data: [['28-Sep-2012', 31.6], ['04-Oct-2012', 0.99], ['03-Oct-2012', -3]]

Detailed Script for your reference:

<script lang="javascript" type="text/javascript">
$(document).ready(function () { 
$('#jqChart').jqChart({ title: { text: 'Animation' }, animation: { delayTime: 1, duration: 2 }, series: [ { type: 'line', title: 'Line', data: [['A', 69], ['B', 57], ['C', 86], ['D', 23], ['E', 70], ['F', 60], ['D', 88], ['H', 22]] } ] }); }); 
</script>
7
  • i fetch a result from mysql by using php. i have used assoc array. here below my code: Commented Oct 10, 2012 at 5:45
  • 2
    Don't post your code in comments.. You can edit your question Commented Oct 10, 2012 at 5:46
  • I got a result like below. $data = Array ( "28-Sep-2012" => 31.6, "04-Oct-2012" => 0.99, "03-Oct-2012" => -3 ); but i need to pass this result to ajax and then convert to like this below: data: [['28-Sep-2012', 31.6], ['04-Oct-2012', 0.99], ['03-Oct-2012', -3]] Commented Oct 10, 2012 at 5:46
  • Detailed Script for your reference: <script lang="javascript" type="text/javascript"> $(document).ready(function () { $('#jqChart').jqChart({ title: { text: 'Animation' }, animation: { delayTime: 1, duration: 2 }, series: [ { type: 'line', title: 'Line', data: [['A', 69], ['B', 57], ['C', 86], ['D', 23], ['E', 70], ['F', 60], ['D', 88], ['H', 22]] } ] }); }); </script> Commented Oct 10, 2012 at 5:48
  • you can edit your question and add all relevant information to the question Commented Oct 10, 2012 at 5:48

2 Answers 2

1

Encode the array using JSON and pass to jQuery.

   json_encode($array);

in jQuery, parse the JSON string to get the array values:

  jQuery.parseJSON(jsonstring);

Check : http://php.net/manual/en/function.json-encode.php and http://api.jquery.com/jQuery.parseJSON/

Place a call from the jQuery to the PHP script using jQuery.get - http://api.jquery.com/jQuery.get/

Sign up to request clarification or add additional context in comments.

1 Comment

Check the edit. You can use any ajax calls. jQuery.get is just one way.
0
$results = mysql_query("SELECT vaccum_value,date FROM vaccum_details where serial_number='10P1005'");
$data1=array();
while ($row = mysql_fetch_array($results)) 
{
    $data1[$row['date']]=$row['vaccum_value'];
}
json_encode($data1);

In your jQuery+ajax

$.ajax({
        type:"POST",
        data:'serial_number=10P1005',
        url: "your_file.php",
        success: function(jsonData){
            var jsonArray = eval('(' + jsonData + ')');

            if(jsonArray.date == 'condition'){
                // some action here
            }else{
                // some other action hera
            }



        }
    },"json");

2 Comments

hi learner thanks for your answer... i can understand your code but i don't know how to join your code with my code... shall i add jqchart code to your code which i have posted on top?
Is this correct? <script lang="javascript" type="text/javascript"> $(document).ready(function () { $('#jqChart').jqChart({ title: { text: 'Animation' }, animation: { delayTime: 1, duration: 2 }, //jQuery.parseJSON(jsonstring); var obj = jQuery.parseJSON(jsonstring); alert(obj); series: [ { type: 'line', title: 'Line', data: [['A', 69], ['B', 57], ['C', 86], ['D', 23], ['E', 70], ['F', 60], ['D', 88], ['H', 22]] } ] }); }); </script>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.