Home › forums › Chart Support › Rendering a Chart with a button click & using json_encode
Tagged: AJAX, chart
I’d like to use a pie chart to show the results of a few calculations. I’ve got 3 fields that the users enters numbers into. Then these numbers are used in calculations in an ajax call. I’ve used json_encode to return this ajax call as an array, with 3 numbers in.
Here is a Js fiddle http://jsfiddle.net/jx9sJ/5/ . In this example the entered numbers are displayed in a graph. I would like to send the entered numbers to ajax for some calculations, and then display them in a graph like this.
When the user clicks ‘submit’ the 3 entered numbers are used in calculations by ajax, & then returned json_encode($total);.
My code so far:
$total['tot1'] = $numwelds + $numconwelds + $mpcountrys ;
$total['tot2'] = $numwelds + $numconwelds + $fortot2 ;
$total['tot3'] = ($numwelds + $numconwelds) + $fortot2 / $fortot3;
$response = json_encode($total);
An example of the array in $response (by print_r) :
Array ( [tot1] => 3 [tot2] => 5 [tot3] => 1 )
How can I tie json_encode($total); to a graph to display the calculated results please? When the user clicks ‘submit’
Just to clarify:
I’m struggling to create the graph from the values, which are in json_encode. How can this be done? So all this is done when the user clicks a button
Please ignore this now. I’ve posted another post with a more accurate question.
You must be logged in to reply to this topic.