Code Comments
Programming Forum and web based access to our favorite programming groups.Hallo, kennt sich jemand mit der Diagramm-Library jpgraph aus? Ich versuche Werte in ein Diagramm zu schreiben, welche ich aus einer mysql-DB auslese im Diagramm auf http://www.rideon.ch/php/schnee.php (ein Ort auswählen und "Zeigen" klicken) wird aber nur die eine Kurve mit den fixen ($ydata2 = array(1,19,15,7,22,14,5,9,21,13);) Werten angezeigt, wesshalb? [Code Chart.php] <?php // Code that uses the jpgraph library include ( '../jpgraph/src/jpgraph.php'); include ('../jpgraph/src/jpgraph_line.php'); /* Datenbankserver - In der Regel die IP */ $db_server = "localhost"; /* Datenbankname */ $db_name = "usr_web2_1 "; /* Datenbankuser */ $db_user = "web2"; /* Datenbankpasswort */ $db_passwort = "5thelement"; /* Erstellt Connect zu Datenbank her */ $db = @MYSQL_CONNECT($db_server,$db_user,$db_p asswort) or die (); $db_check = @MYSQL_SELECT_DB($db_name); if($db) { $sqlwhere="WHERE location=\"$location\""; $result = mysql_query("SELECT * FROM schnee $sqlwhere ORDER BY location, date DESC"); while ($row = mysql_fetch_array ($result)) { $ydata[$i]=$row[snowheight]; $i++; //zählvariable inkrementieren } //********** DIGRAMM ************ //$ydata = array(11,3,8,12,5,1,9,13,5,50); $ydata2 = array(1,19,15,7,22,14,5,9,21,13); // Create the graph. These two calls are always required $graph = new Graph(500,400,"auto"); $graph->SetScale("textlin"); // Create the linear plot $lineplot=new LinePlot($ydata); $lineplot2=new LinePlot($ydata2); // Add the plot to the graph $graph->Add($lineplot); $graph->Add($lineplot2); $graph->img->SetMargin(40,20,20,40); $graph->title->Set("$location"); $graph->xaxis->title->Set("Datum [yyyy-mm-dd]"); $graph->yaxis->title->Set("Schneehöhe [cm]"); $graph->title->SetFont(FF_FONT1,FS_BOLD); $graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD); $graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD); $lineplot->SetColor("blue"); $lineplot->SetWeight(2); $lineplot2->SetColor("orange"); $lineplot2->SetWeight(2); $graph->yaxis->SetColor("red"); $graph->yaxis->SetWeight(2); $graph->SetShadow(); // Display the graph $graph->Stroke(); } ?> [/Code Chart.php] Danke! -- roN www.rideon.ch
Post Follow-up to this messageRon Eggler wrote: > Hallo, > > kennt sich jemand mit der Diagramm-Library jpgraph aus? > Ich versuche Werte in ein Diagramm zu schreiben, welche ich aus einer > mysql-DB auslese im Diagramm auf http://www.rideon.ch/php/schnee.php > (ein Ort auswählen und "Zeigen" klicken) wird aber nur die eine Kurve > mit den fixen ($ydata2 = array(1,19,15,7,22,14,5,9,21,13);) Werten > angezeigt, wesshalb? > [Code Chart.php] > <?php > // Code that uses the jpgraph library > include ( '../jpgraph/src/jpgraph.php'); > include ('../jpgraph/src/jpgraph_line.php'); > > /* Datenbankserver - In der Regel die IP */ > $db_server = "localhost"; > /* Datenbankname */ > $db_name = "usr_web2_1 "; > /* Datenbankuser */ > $db_user = "web2"; > /* Datenbankpasswort */ > $db_passwort = "5thelement"; > > /* Erstellt Connect zu Datenbank her */ > $db = @MYSQL_CONNECT($db_server,$db_user,$db_p asswort) or die (); > $db_check = @MYSQL_SELECT_DB($db_name); > if($db) > { > $sqlwhere="WHERE location=\"$location\""; > $result = mysql_query("SELECT * FROM schnee $sqlwhere ORDER BY > location, date DESC"); > while ($row = mysql_fetch_array ($result)) > { > $ydata[$i]=$row[snowheight]; > $i++; //zählvariable inkrementieren > } > //********** DIGRAMM ************ > //$ydata = array(11,3,8,12,5,1,9,13,5,50); > $ydata2 = array(1,19,15,7,22,14,5,9,21,13); > > // Create the graph. These two calls are always required > $graph = new Graph(500,400,"auto"); > $graph->SetScale("textlin"); > > // Create the linear plot > $lineplot=new LinePlot($ydata); > > $lineplot2=new LinePlot($ydata2); > > // Add the plot to the graph > $graph->Add($lineplot); > $graph->Add($lineplot2); > > $graph->img->SetMargin(40,20,20,40); > $graph->title->Set("$location"); > $graph->xaxis->title->Set("Datum [yyyy-mm-dd]"); > $graph->yaxis->title->Set("Schneehöhe [cm]"); > > $graph->title->SetFont(FF_FONT1,FS_BOLD); > $graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD); > $graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD); > > $lineplot->SetColor("blue"); > $lineplot->SetWeight(2); > > $lineplot2->SetColor("orange"); > $lineplot2->SetWeight(2); > > $graph->yaxis->SetColor("red"); > $graph->yaxis->SetWeight(2); > $graph->SetShadow(); > > // Display the graph > $graph->Stroke(); > } > > [/Code Chart.php] > > Danke! Okay, ich hab's... Danke trozdem! :)
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.