hi i know its kind of to late to post, but im not so sure if i understand ur code!!!..i have this case!!, a table 14(row)x10(col), the varible $getData_t1 etc.. is the variable where u get the query, i mean $getData=mysql_query("select * from table")?
......or i need to make a getdata, which will do:
<?phpim quite lost!!!! 0_0!!!
// This is just an example of reading server side data and sending it to the client.
// It reads a json formatted text file and outputs it.
$string = file_get_contents("sampleData.json");//me: insted of "sampleData.json" send something else???
maybe the goo2.php!!!??
echo $string;
// Instead you can query your database and parse into JSON etc etc
?>
Well, i thing is alredy resolve :) , the goo2.php it alredy show something but the main thing is the
grafic with the goochart.html file, its still blank, i have been changing a few things, but same result!!.
Attach the "View page source code" of the goochart.html.
<html xmlns="http://www.w3.org/1999/xhtml"><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>GRAFICAS SEMANALES</title> </head> <body>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript" src="jquery-1.6.2.min.js"></script> <script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var jsonData = $.ajax({
url: "http://localhost/MyProject/getdata.php",//a chage this part to see what will happend,firt it was the goo2.php!!
dataType:"json",
async: false
}).responseText;
var data = google.visualization.DataTable(jsonData);
var options = {
title: 'SALIDAS SEMANALES',
hAxis: {title: 'SEMANAS', titleTextStyle: {color: 'red'}}
};
var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script><script src="https://www.google.com/uds/?file=visualization&v=1&packages=corechart" type="text/javascript"></script><script src="https://www.google.com/uds/api/visualization/1.0/d7d36793f7a886b687850d2813583db9/format+es,default,corechart.I.js" type="text/javascript"></script>
cause if is that, i have been looking and it only send warning of the other pages i have open!!!
18 function drawChart() {
19 var jsonData = $.ajax({
20 url: "http://localhost/MyProject/getdata.php",
21 dataType:"json",
.......json support | enabled |
json version | 1.2.1 |
Hi asgallant,
Seeing Diana's example, I tried doing something similar with a Line graph but it's not coming out as I'd like.
It displays the three series but links them all together instead of individually displaying them (lineChart.jpg).
What I'm trying to achieve, is something similar to how it's displayed in Excel (chart_xls.jpg).
If you could help me in the right direction, I'd appreciate it alot as I have been trying various things and the outcome
isn't what I'm expecting.
José
Hey guys, i was tryng using the asgallant's exemple, but i've not sucess.the browser generate the right code, and if i copy and paste the code to playground, it works! why it doesnt works here?take a look in my code:<script type="text/javascript">function drawVisualization() {// Create and populate the data table.var data = new google.visualization.DataTable();data.addColumn('number', 'Sensor');<?phpforeach ($val as $valores) {echo "data.addRows([[$valores]]);";}?>// Create and draw the visualization.new google.visualization.ImageSparkLine(document.getElementById('visualization')).draw(data, null);}google.setOnLoadCallback(drawVisualization);</script>I've sure that $val isnt empty!Cya!
hi . u know i have a problem since some months ago. i dondt speak english very well. but i ll try .. well i have a file named report.php and this file contains this form like this<form id="generalreporte" method="post" action="reportegeneral.php"><div id="general" style="display: none; text-align: center;"><label style="font-size:medium">Fecha de:</label> <input type="date" name="fecha1" required/> <label style="font-size:medium">entre</label> <input type="date" name="fecha2" required/><br/><br/><input type="submit" value="Enviar"/></div></form>and i use a library named jquery.form in order to send the values with ajax to another file named genera.php in this file i just want to do a query mysql with te values and then generate a google chart pie with ajax but in the same file that contains the form. its posible this . please help me my friend
Ok my friend Im gonna work in this. Ok. And i will tell u when i finish It. A lot of thanks .
my work is to do a survey ... and those are the answers u know i just want to show in a certain date how many people responde.... so in my sql query i obtained the results from my survey........ u know i have a question in my survey,,,, and i just want to know how many people answered to each answer......
Yes my friend asome. U know im really learning a lot. Well i use a library named jquery.form.js in orden to send with ajax. In this moment i Have to go at my school. When i come back Im gonna send u my file witch has the form And the jquery.form.js thanks a lot for Ur time my friend.
Hi my friend. Thanks a lot for answering. I wll Try this when i arrive at home
Hi asgallant, thank you very much for th taking the time to help others. i have a question if you dont mind, i followed Diana´s sample and got it to work, well sort of, i used my onw db and managed to show the graph and everithing, the only thing is that my mysql query running in phpmyadmin shows 55 records and my json result shows only 14 records, how is that possible ???
Yesterday i was working in the pie chart wich u help me to do. And i was able to update the same pie chart with new data...... do u remeber that i Have a file with a form this form has 2 fileds type=date. Well And then another file obtains the values .... But now i want to do 2 mysql querys with the values. And generate 2 json results completly diferent And send them to the file wich has the form And generate 2 pie charts in the same file And in the same time
Hi my friend Im gonna send u my code in orden to explain me better. ... i Have a question can i download the google library to draw the pie charts in orden to import It on my proyect. Cause when i Have not Internet It doesnt work
Yes ian haylock he is very kind. I wish there were more people like andrew ....
Hello asgallant, I see your still very active in helping other people which is very kind of you!
Since you've last helped me, I've added just a couple of minor things but I'm still trying to figure out how to dynamically change/pass a value to the sql string so as it can plot the chart from different data. The two files I'm still using are 'chart.php' & 'chartdata.php'. How do I get chart.php to pass this variable and have the data file receive it? The sql fields are the same, it's just the column 'id_testKey' that will dictate what data is requested.
José
On Wednesday, October 17, 2012 5:40:15 PM UTC-7, asgallant wrote:
You're welcome.
On Wednesday, October 17, 2012 7:06:01 PM UTC-4, Jose wrote:Thank you very much, that helped! Now I'll use other chart options to fine tune it a bit to look similar to my excel charts.
Really appreciate the help asgallant!
On Wednesday, October 17, 2012 10:31:40 AM UTC-7, asgallant wrote:D'oh! My mistake, I did change something else. The (float) typing converts null into 0, so you have to test for null and handle it specially. In your php file, the while loop should look like this:
while($r = mysql_fetch_assoc($sth)) {$temp = array();
$temp[] = array('v' => (float) $r['PsiBar']);$temp[] = array('v' => (is_null($r['prodPerct1'])) ? null : (float) $r['prodPerct1']);$temp[] = array('v' => (is_null($r['prodPerct2'])) ? null : (float) $r['prodPerct2']);$temp[] = array('v' => (is_null($r['prodPerct3'])) ? null : (float) $r['prodPerct3']);
$rows[] = array('c' => $temp);}
although, since your data is already in numerical form (and thus you don't have to force it to be type float), you can go with the simpler:
while($r = mysql_fetch_assoc($sth)) {$temp = array();
$temp[] = array('v' => $r['PsiBar']);$temp[] = array('v' => $r['prodPerct1']);$temp[] = array('v' => $r['prodPerct2']);$temp[] = array('v' => $r['prodPerct3']);
$rows[] = array('c' => $temp);}
It's also a good idea to force the mime type to application/json by setting the header, before you echo the json:header("Content-type: application/json");echo $jsonTable;On Wednesday, October 17, 2012 10:54:15 AM UTC-4, asgallant wrote:I used your code exactly as it appears in the files you posted, except for the modifications mentioned. I didn't save a copy, though, so I can't post them back. I'll see if I can duplicate it later today.
On Wednesday, October 17, 2012 10:11:01 AM UTC-4, Jose wrote:Asgallant, I tried it again and still the same results, although I did add that var option but it didn't help. I'm wondering if its something else in your scripts/code that is different than mine. If you could post those, that would be great.
As another non sufficient way, could three separate SQL calls be made then plot the results onto the same chart?
On Tuesday, October 16, 2012 10:16:00 AM UTC-7, asgallant wrote:I duplicated your table and ran the query, and Method 2 looked right to me. I had to make 1 small change to the SQL to make it run (but that could be a quirk of my MySQL install), and 1 change to the chart options. The SQL looked like this:SELECTfoo.PsiBar,IF(prodPerct1 = 0, null, foo.prodPerct1) as prodPerct1,IF(prodPerct2 = 0, null, foo.prodPerct2) as prodPerct2,IF(prodPerct3 = 0, null, foo.prodPerct3) as prodPerct3FROM (SELECTPsiBar,SUM(IF(id_sample = 1, prodPerct, null)) AS prodPerct1,SUM(IF(id_sample = 2, prodPerct, null)) AS prodPerct2,SUM(IF(id_sample = 3, prodPerct, null)) AS prodPerct3FROM tbl_dilutionGROUP BY PsiBar) AS fooand I set the "interpolateNulls" chart option to true:var options = {title: 'Line Chart Test',interpolateNulls: true};
On Tuesday, October 16, 2012 12:51:40 PM UTC-4, Jose wrote:I gave both a try and neither looked as it should. Method 2 displays the chart as it did previous where it was plotting the null '0' values.
On Monday, October 15, 2012 9:38:58 PM UTC-7, asgallant wrote:Hmmm...I can see two ways of handling that. One results in a messy DataTable, and will probably work; the other results in a cleaner DataTable, but might not work.Method 1: change the SQL statement to this:SELECTPsiBar,IF(id_sample = 1, prodPerct, null) AS prodPerct1,IF(id_sample = 2, prodPerct, null) AS prodPerct2,IF(id_sample = 3, prodPerct, null) AS prodPerct3FROM tbl_dilutionremoving the sums and the group by clause. This will result in more rows of data (with duplicate domain column entries) than necessary.Method 2: this will work only if 0 is not a valid value for your data points to have. Change the SQL to this:GROUP BY PsiBarSELECTPsiBar,IF(prodPerct1 = 0, null, prodPerct1) as prodPerct1,IF(prodPerct2 = 0, null, prodPerct2) as prodPerct2,IF(prodPerct3 = 0, null, prodPerct3) as prodPerct3FROM (SELECTPsiBar,SUM(IF(id_sample = 1, prodPerct, null)) AS prodPerct1,SUM(IF(id_sample = 2, prodPerct, null)) AS prodPerct2,SUM(IF(id_sample = 3, prodPerct, null)) AS prodPerct3FROM tbl_dilution) AS foowhich tests to see if the sum is 0, and if it is, sets the value to null instead. The DataTable will be cleaner, but it won't work if your values can be 0.On Monday, October 15, 2012 6:45:51 PM UTC-4, Jose wrote:asgallant, you are right, I am trying to get three lines plotted for each 'id_sample'. Within each id group, there are 12 plot points.
I've tried the code you provided, thanks, but it appears to also plot the null values '0' between each data point. How do I fix this?
{"cols":[{"label":"PsiBar","type":"number"},{"label":"Series 1","type":"number"},{"label":"Series 2","type":"number"},{"label":"Series 3","type":"number"}],"rows":[{"c":[{"v":0.39},{"v":0.36},{"v":0},{"v":0}]},{"c":[{"v":0.5},{"v":0},{"v":0.26},{"v":0.11}]},{"c":[{"v":0.56},{"v":0.49},{"v":0.34},{"v":0}]},{"c":[{"v":0.57},{"v":0},{"v":0},{"v":0.16}]},{"c":[{"v":0.84},{"v":0.56},{"v":0.41},{"v":0.15}]},{"c":[{"v":1.01},{"v":0.62},{"v":0.42},{"v":0}]},{"c":[{"v":1.02},{"v":0},{"v":0},{"v":0.24}]},{"c":[{"v":1.3},{"v":0.66},{"v":0.49},{"v":0}]},{"c":[{"v":1.31},{"v":0},{"v":0},{"v":0.26}]},{"c":[{"v":1.45},{"v":0.66},{"v":0.5},{"v":0.27}]},{"c":[{"v":1.74},{"v":0},{"v":0.52},{"v":0}]},{"c":[{"v":1.75},{"v":0.68},{"v":0},{"v":0.28}]},{"c":[{"v":2.1},{"v":0},{"v":0},{"v":0.28}]},{"c":[{"v":2.11},{"v":0},{"v":0.52},{"v":0}]},{"c":[{"v":2.12},{"v":0.68},{"v":0},{"v":0}]},{"c":[{"v":2.57},{"v":0},{"v":0.49},{"v":0.27}]},{"c":[{"v":2.58},{"v":0.65},{"v":0},{"v":0}]},{"c":[{"v":3.07},{"v":0},{"v":0},{"v":0.25}]},{"c":[{"v":3.09},{"v":0.6},{"v":0.46},{"v":0}]},{"c":[{"v":3.56},{"v":0.56},{"v":0},{"v":0.23}]},{"c":[{"v":3.57},{"v":0},{"v":0.42},{"v":0}]},{"c":[{"v":4.23},{"v":0},{"v":0},{"v":0.21}]},{"c":[{"v":4.34},{"v":0},{"v":0.39},{"v":0}]},{"c":[{"v":4.36},{"v":0.51},{"v":0},{"v":0}]}]}
Really appreciate your help on this!
On Thursday, October 11, 2012 12:43:03 PM UTC-7, asgallant wrote:You're not charting 3 series there, you have 1 series. Looking at your SQL table, I would guess that you want to display one series for each sample id, right? If so, then you need to break out the "prodPerct" column into 3 different columns - 1 for each series. This is probably best achieved in SQL, maybe with a query like this:SELECTPsiBar,SUM(IF(id_sample = 1, prodPerct, null)) AS prodPerct1,SUM(IF(id_sample = 2, prodPerct, null)) AS prodPerct2,SUM(IF(id_sample = 3, prodPerct, null)) AS prodPerct3FROM tbl_dilutionGROUP BY PsiBarand then use this to build the table:$table['cols'] = array(array('label' => 'PsiBar', 'type' => 'number'),array('label' => 'Series 1', 'type' => 'number')array('label' => 'Series 2', 'type' => 'number')array('label' => 'Series 3', 'type' => 'number')
);$rows = array();while($r = mysql_fetch_assoc($sth)) {$temp = array();
$temp[] = array('v' => (float) $r['psiBar']);$temp[] = array('v' => (float) $r['prodPerct1']);$temp[] = array('v' => (float) $r['prodPerct2']);$temp[] = array('v' => (float) $r['prodPerct3']);
$rows[] = array('c' => $temp);}
On Thursday, October 11, 2012 12:50:04 PM UTC-4, Jose wrote:Hi asgallant,
Seeing Diana's example, I tried doing something similar with a Line graph but it's not coming out as I'd like.
It displays the three series but links them all together instead of individually displaying them (lineChart.jpg).
What I'm trying to achieve, is something similar to how it's displayed in Excel (chart_xls.jpg).
If you could help me in the right direction, I'd appreciate it alot as I have been trying various things and the outcome
isn't what I'm expecting.
José
On Wednesday, September 26, 2012 10:11:01 AM UTC-7, asgallant wrote:What is throwing that error message? Is it PHP?You will have to adjust the data types to the type of data you are using, so if your first column isn't type string, you need to change it to something else in the column definitions (this goes for all columns - types must always match). Also, the (string) typecasting in this line:$temp[] = array('v' => (string) $r['PLACA']);is probably not necessary, unless you have a non-string data type that you need to specifically convert into a string.
If you can post a link to the page, I can help debug things on the javascript end, if it turns out that is where the problem is.
On Wednesday, September 26, 2012 4:47:20 AM UTC-4, Barbara Gerstl wrote:That is what I did... but, when opening goochart2.html, the result is the Error-Massage "string".
I think, it has something to do with the field settings of the columns. Do you have any tipps?
Thank you!
Am Montag, 24. September 2012 19:26:26 UTC+2 schrieb asgallant:You can extrapolate from the code that the table has 6 columns: PLACA, S1, S2, S3, S4, S5.
On Monday, September 24, 2012 10:15:44 AM UTC-4, Barbara Gerstl wrote:Hello Diana!
Thank you very much for showing the whole process on how to combine Google Graph API with a MySQL-Database. That is exactly what I am looking for.
I tried to rebuild your example and I am having problems with the structure of the database/field settings. Can you show me structure and field settings of the table "bd_salidas"?
Thank you for your answer.
Barbara
Am Mittwoch, 5. September 2012 21:56:35 UTC+2 schrieb Diana Flores:yeaaaaaaahhhHHHH!!!!, we did it!!!!!!!!!!!!!. well at first i tried the .DataTable(jsonData); but it gave me errors but i put the JSON.parse(jsonData)); and it works!!!!!!!!!!!!!!!!!!....im so happy!!! i will attach the files in case someone has the same problem!!!!!!!!....really really grateful, cause with your help i learned a lot of things!!!!....one month ago I was "what its php or mysql....JSON O_O???" i think its a lot, but thanks!!!!