|
bar graph empty data from mysql
Author |
Message |
Jarod51
Regular pChart user
Joined: Thu Sep 01, 2011 8:47 am Posts: 11
|
bar graph empty data from mysql
Hi there, I'm posting a message on this forum because I have some troubleshooting with pchart lib. Actually the picture generated by pchart is always empty in spite of existing values in output. I don't understand which is wrong into my source code. The goal is to draw a bar graph. Hope i could find some help here . Here my source code : Code: <?php //database require_once "config.php";
// Standard inclusions include("pChart/pData.class"); include("pChart/pChart.class");
$age1 = $_POST["age1"];
$DataSet = new pData(); foreach($_POST['admin'] as $categ){
//generate a random key for the picture file $key=rand();
$sql = "select count(distinct `IDPat`) as Nombre, annee, CIMO from export where CIMO like '".$categ."' and age>=".$age1." group by annee order by annee desc"; $result = mysql_query($sql) or die(mysql_error());
//init var $Nombre=""; $annee="";
echo "<table border='1'> <tr> <th>Nombre</th> <th>annee</th> <th>LesionCIMO</th>
</tr>"; while($row = mysql_fetch_assoc($result)) { echo "<tr>"; echo "<td>" . $row['Nombre'] . "</td>"; echo "<td>" . $row['annee'] . "</td>"; echo "<td>" . $row['CIMO'] . "</td>"; echo "</tr>"; } echo "</table>"; echo "<br/><br/>";
/* Push the results of the query in an array */ while($rowz = mysql_fetch_array($result)) { $Nombre[] = $rowz['Nombre']; $annee[] = $rowz['annee']; }
$DataSet->AddPoint($Nombre,"Nombre"); $DataSet->AddPoint($annee,"Annee"); $DataSet->AddAllSeries(); $DataSet->RemoveSerie("Annee"); $DataSet->SetAbsciseLabelSerie("Annee"); $DataSet->SetSerieName("Nombre","Nombre"); $DataSet->SetYAxisName("Nombre"); // Initialise the graph $Test = new pChart(700,230); $Test->setFontProperties("Fonts/tahoma.ttf",8); $Test->setGraphArea(50,30,585,200); $Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240); $Test->drawRoundedRectangle(5,5,695,225,5,230,230,230); $Test->drawGraphArea(255,255,255,TRUE); $Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2,TRUE); $Test->drawGrid(4,TRUE,230,230,230,50);
// Draw the 0 line $Test->setFontProperties("Fonts/tahoma.ttf",6); $Test->drawTreshold(0,143,55,72,TRUE,TRUE);
// Draw the bar graph $Test->drawOverlayBarGraph($DataSet->GetData(),$DataSet->GetDataDescription());
// Finish the graph $Test->setFontProperties("Fonts/tahoma.ttf",8); $Test->drawLegend(600,30,$DataSet->GetDataDescription(),255,255,255); $Test->setFontProperties("Fonts/tahoma.ttf",10); $Test->drawTitle(50,22,"Example",50,50,50,585); $Test->Render("example$key.png"); }//end foreach
mysql_close($con) ?>
|
Thu Sep 01, 2011 9:02 am |
|
|
jean-damien
Site Admin
Joined: Thu Dec 02, 2010 2:31 pm Posts: 409 Location: France
|
Re: bar graph empty data from mysql
at a first sight I can say that at least the drawOverlayBarGraph() function does not exists ;o)
JD.
|
Thu Sep 01, 2011 9:08 am |
|
|
Jarod51
Regular pChart user
Joined: Thu Sep 01, 2011 8:47 am Posts: 11
|
Re: bar graph empty data from mysql
Hi Jean-Damien, Thanks for your reply, I changed drawOverlayBarGraph() by drawBarGraph, same result the picture generated doesn't contain bar graph just axis
|
Thu Sep 01, 2011 9:10 am |
|
|
jean-damien
Site Admin
Joined: Thu Dec 02, 2010 2:31 pm Posts: 409 Location: France
|
Re: bar graph empty data from mysql
|
Thu Sep 01, 2011 9:15 am |
|
|
Jarod51
Regular pChart user
Joined: Thu Sep 01, 2011 8:47 am Posts: 11
|
Re: bar graph empty data from mysql
yeah thx, even if a drawBarChart the pic doesn't contain graphic only axis. Do you have any idea what's wrong ?
|
Thu Sep 01, 2011 9:19 am |
|
|
jean-damien
Site Admin
Joined: Thu Dec 02, 2010 2:31 pm Posts: 409 Location: France
|
Re: bar graph empty data from mysql
I am really disapointed by your code. Seems to be a mix of 1.0 and 2.0. Even the class names looks strange. Which version of the library are you currently using? Mixing HTML outputs with picture rendering isn't a nice solution, I would advice to split your script : 1 for the HTML part, 1 for the picture generation : myPage.phpCode: <IMG SRC='mypChartScript.php'>
mypChartScript.phpCode: ..image creation code..
JD.
|
Thu Sep 01, 2011 9:30 am |
|
|
Jarod51
Regular pChart user
Joined: Thu Sep 01, 2011 8:47 am Posts: 11
|
Re: bar graph empty data from mysql
I actually downloaded the pChart.1.27d on this website. I didn't see where is the 2.0 version. I followed the tutorial https://wiki.pchart.net/doc.mysql.integration.html and try to adapt the code with my need. I did some tests, I actually removed the <table> and I let only the pchart code in my php page. This time the .png contains the graphic with values. So I under that we cannot mix html content and pchart graphic in the same page. I have to follow your advice to combine both ? such as : Code: foreach($_POST['admin'] as $categ){ ... echo "<table border='1'> <tr> ...
<IMG SRC='mypChartScript.php'> } //end foreach
|
Thu Sep 01, 2011 9:40 am |
|
|
jean-damien
Site Admin
Joined: Thu Dec 02, 2010 2:31 pm Posts: 409 Location: France
|
Re: bar graph empty data from mysql
Good to hear that it's working ;o) pChart 1.x isn't supported anymore, you should move to the 2.x version ( http://www.pchart.net) It is really difficult -but possible using IMG encoding- to mix HTML output and picture generation. The two files options is the more reliable one. Kind regards, JD.
|
Thu Sep 01, 2011 10:00 am |
|
|
Jarod51
Regular pChart user
Joined: Thu Sep 01, 2011 8:47 am Posts: 11
|
Re: bar graph empty data from mysql
i tried to do as you advice me, cut in two parts, it seems not working well. It generates an empty .png, could you please tell me if i'm doing the correct way, I don't know what i have to do to resolve this problem stat.phpCode: <html> <head><title>test</title></head> <body> <?php require_once "config.php";
$age1 = $_POST["age1"];
foreach($_POST['admin'] as $categ){ //random key $key=rand();
echo "$categ <br/>"; $sql = "select count(distinct `IDPat`) as Nombre, annee, CIMO from export where CIMO like '".$categ."' and age>=".$age1." group by annee order by annee desc"; $result = mysql_query($sql) or die(mysql_error()); $Nombre=""; $annee="";
echo "<table border='1'> <tr> <th>Nombre</th> <th>annee</th> <th>CIMO</th>
</tr>"; while($row = mysql_fetch_assoc($result)) { echo "<tr>"; echo "<td>" . $row['Nombre'] . "</td>"; echo "<td>" . $row['annee'] . "</td>"; echo "<td>" . $row['CIMO'] . "</td>"; echo "</tr>"; } echo "</table>"; echo "<br/><br/>";
while($rowz = mysql_fetch_array($result)) { $Nombre[] = $rowz['Nombre']; $annee[] = $rowz['annee']; } include "mypChartScript.php"; }//end foreach
mysql_close($con)
?>
<IMG SRC='mypChartScript.php'> </body> </html>
mypChartScript.phpCode: <?php
include("pChart/pData.class"); include("pChart/pChart.class"); $DataSet = new pData(); $DataSet->AddPoint($Nombre,"Nombre"); $DataSet->AddPoint($annee,"Annee"); $DataSet->AddAllSeries(); $DataSet->RemoveSerie("Annee"); $DataSet->SetAbsciseLabelSerie("Annee"); $DataSet->SetSerieName("Nombre","Nombre"); $DataSet->SetYAxisName("Nombre"); // Initialise the graph $Test = new pChart(700,230); $Test->setFontProperties("Fonts/tahoma.ttf",8); $Test->setGraphArea(50,30,585,200); $Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240); $Test->drawRoundedRectangle(5,5,695,225,5,230,230,230); $Test->drawGraphArea(255,255,255,TRUE); $Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2,TRUE); $Test->drawGrid(4,TRUE,230,230,230,50);
// Draw the 0 line $Test->setFontProperties("Fonts/tahoma.ttf",6); $Test->drawTreshold(0,143,55,72,TRUE,TRUE);
// Draw the bar graph $Test->drawBarGraph($DataSet->GetData(),$DataSet->GetDataDescription());
// Finish the graph $Test->setFontProperties("Fonts/tahoma.ttf",8); $Test->drawLegend(600,30,$DataSet->GetDataDescription(),255,255,255); $Test->setFontProperties("Fonts/tahoma.ttf",10); $Test->drawTitle(50,22,"Example",50,50,50,585); $Test->Render("example.png"); ?>
|
Thu Sep 01, 2011 10:03 am |
|
|
Jarod51
Regular pChart user
Joined: Thu Sep 01, 2011 8:47 am Posts: 11
|
Re: bar graph empty data from mysql
jean-damien,
I think it is not possible to combine table content with pchart graphic on php web page. Am I right ? Otherwise, I cannot see how to mix both.
|
Thu Sep 01, 2011 11:59 am |
|
|
Who is online |
Users browsing this forum: No registered users and 7 guests |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum
|
|
|