Graph Representation of data using PHP and JavaScript -


Hello there I need to represent the data in the graph form (chart form). I am using a jQuery plugin for this. The problem I have is that when I'm using a PHP array that does not work for me

The code I'm using is here.

  & lt; Html & gt; & Lt; Top & gt; & Lt; Title & gt; JSChart & lt; / Title & gt; & Lt; Script type = "text / javascript" src = "../../../ source / jscrt.js" & gt; & Lt; / Script & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; Div id = "graph" & gt; Loading graph ... & lt; / Div & gt; & Lt ;? Php $ phpArray = array ("Peter" =>, "35", "Ben" =>, "37", "joe" =>, "43"); $ Aa = json_encode ($ phpArray); ? & Gt; & Lt; Script type = "text / javascript" & gt; Var myData = & lt ;? Php echo $ aa; ? & Gt ;; Alert (MyData); Var color = ['# AFT202', '# EC7A00', '# FCD 200', '# 81C714']; Var myChart = new JSChart ('graph', 'bar'); MyChart.setDataArray (MyData); MyChart.colorizeBars (color); MyChart.setTitle ('Year-by-Year Growth in Home Broadband penetration in the US'); MyChart.setTitleColor ('# 8E8E8E'); MyChart.setAxisNameX (''); MyChart.setAxisNameY ('%'); MyChart.setAxisColor ('# C4C4C4'); MyChart.setAxisNameFontSize (16); MyChart.setAxisNameColor ('# 999'); MyChart.setAxisValuesColor ('# 7E7E7E'); MyChart.setBarValuesColor ('# 7E7E7E'); MyChart.setAxisPaddingTop (60); MyChart.setAxisPaddingRight (140); MyChart.setAxisPaddingLeft (150); MyChart.setAxisPaddingBottom (40); MyChart.setTextPaddingLeft (105); MyChart.setTitleFontSize (11); MyChart.setBarBorderWidth (1); MyChart.setBarBorderColor ('# C4C4C4'); MyChart.setBarSpacingRatio (50); MyChart.setGrid (wrong); MyChart.setSize (616, 321); MyChart.setBackgroundImage ('chart_bg.jpg'); MyChart.draw (); & Lt; / Script & gt; & Lt; / Body & gt; & Lt; / Html & gt;   

And the code below is going on completely. (With JavaScript array)

  & lt; Script type = "text / javascript" & gt; Var myData = The new array (['March 04-March 05'], ['March 05-March 06', 28], ['March 06-March 07', 12], ['March 07-March 08', 17] ]); Alert (MyData); Var color = ['# AFT202', '# EC7A00', '# FCD 200', '# 81C714']; Var myChart = new JSChart ('graph', 'bar'); MyChart.setDataArray (MyData); MyChart.colorizeBars (color); MyChart.setTitle ('Year-by-Year Growth in Home Broadband penetration in the US'); MyChart.setTitleColor ('# 8E8E8E'); MyChart.setAxisNameX (''); MyChart.setAxisNameY ('%'); MyChart.setAxisColor ('# C4C4C4'); MyChart.setAxisNameFontSize (16); MyChart.setAxisNameColor ('# 999'); MyChart.setAxisValuesColor ('# 7E7E7E'); MyChart.setBarValuesColor ('# 7E7E7E'); MyChart.setAxisPaddingTop (60); MyChart.setAxisPaddingRight (140); MyChart.setAxisPaddingLeft (150); MyChart.setAxisPaddingBottom (40); MyChart.setTextPaddingLeft (105); MyChart.setTitleFontSize (11); MyChart.setBarBorderWidth (1); MyChart.setBarBorderColor ('# C4C4C4'); MyChart.setBarSpacingRatio (50); MyChart.setGrid (wrong); MyChart.setSize (616, 321); MyChart.setBackgroundImage ('chart_bg.jpg'); MyChart.draw (); & Lt; / Script & gt; & Lt; / Body & gt; & Lt; / Html & gt;  

Chart object is expecting 2D array (an array inside array) .

If you look in the HTML source, you will see that json_encode is giving you an object which will look something like this:

  {"  

Try to use this:

  create_2d_array function," 35 "," ben "," 37 "," joe " "43"} ($ array) {if (count ($ array) == 0) "[]" returns; $ result = "["; foreign currency ($ array = $ value as $ key) {$ Result. = "[\" $ Key \ ", $ value],";} $ result = substart ($ result, 0, strangel ($ result) - 2); Returns $ result "]";}   

and in the JavaScript area:

  var myData = & lt ;? php echo create_2d_array ($ phpArray). ';';? & Gt;;    

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -