CronJob-Service
bei SELFPHP mit ...
|
+ minütlichen Aufrufen
+ eigenem Crontab Eintrag
+ unbegrenzten CronJobs
+ Statistiken
+ Beispielaufrufen
+ Control-Bereich
Führen Sie mit den CronJobs von
SELFPHP zeitgesteuert Programme
auf Ihrem Server
aus. Weitere Infos
|
:: Anbieterverzeichnis ::
Globale Branchen
Informieren Sie sich über ausgewählte Unternehmen im Anbieterverzeichnis von SELFPHP
:: Newsletter ::
Abonnieren Sie hier den kostenlosen
SELFPHP Newsletter!
|
PHP Grundlagen Hier kann über grundlegende Probleme oder Anfängerschwierigkeiten diskutiert werden |
19.10.2012, 14:16:34
|
Anfänger
|
|
Registriert seit: Oct 2012
Alter: 37
Beiträge: 26
|
|
Textdatei mittels JPGraph darstellen
Hallo,
ich habe gerade angefangen PHP zu lernen und will nun eine Textdatei mit 9 Spalten an Werten mit PHP in ein Array einlesen und dann mit JPGraph darstellen lassen. Ich bin jetzt so weit gekommen, dass ich die Werte aufgespalten habe und auch in einzelne Arrays aufgeteilt habe. Nun möchte ich diese dann mit lineplot einlesen, jedoch bekomme ich nur die Fehlermeldung:
JpGraph Error: 25044 Cannot use auto scaling since it is impossible to determine a valid min/max value of the Y-axis (only null values).
Greif ich irgendwie auf ein falsches Array zu?
Hier noch mein Code:
PHP-Code:
<?php
$datei = file("Mappe1.txt");
$Dates = array();
$Times = array();
$Oberpegel = array();
$Unterpegel = array();
$Durchfluss = array();
$OS1 = array();
$US1 = array();
$OS2 = array();
$US2 = array();
include("jpgraph/src/jpgraph.php");
include("jpgraph/src/jpgraph_line.php");
$graph = new graph(1000,500,"auto");
$graph->SetScale("textlin");
foreach($datei AS $ausgabe)
{
$x = explode(";", $ausgabe);
//fuege neue elemente zu den bestehenden arrays hinzu. array_push fuegt am ende ein
//tue das fuer jede zeile in $datei
array_push($Dates,$x[0]);
array_push($Times ,$x[1]);
array_push($Oberpegel ,$x[2]);
array_push($Unterpegel ,$x[3]);
array_push($Durchfluss ,$x[4]);
array_push($OS1 ,$x[5]);
array_push($US1 ,$x[6]);
array_push($OS2 ,$x[7]);
array_push($US2,$x[8]);
}
$lineplot2=new linePlot($Oberpegel);
$lineplot3=new linePlot($Unterpegel);
$lineplot4=new linePlot($Durchfluss);
$lineplot5=new linePlot($OS1);
$lineplot6=new linePlot($US1);
$lineplot7=new linePlot($OS2);
$lineplot8=new linePlot($US2);
$graph->Add($lineplot2);
$graph->Add($lineplot3);
$graph->Add($lineplot4);
$graph->Add($lineplot5);
$graph->Add($lineplot6);
$graph->Add($lineplot7);
$graph->Add($lineplot8);
// Grafik Formatieren
$graph->img->SetMargin(40,20,20,40);
$graph->title->Set("Neu Lübbenau");
$graph->xaxis->title->Set("Time");
$graph->yaxis->title->Set("Y-title");
$graph->title->SetFont(FF_FONT1,FS_BOLD);
$graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD);
$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);
$lineplot2->SetColor("blue");
$lineplot2->SetWeight(2);
$lineplot3->SetColor("orange");
$lineplot3->SetWeight(2);
$lineplot4->SetColor("red");
$lineplot4->SetWeight(2);
$lineplot5->SetColor("black");
$lineplot5->SetWeight(2);
$lineplot6->SetColor("green");
$lineplot6->SetWeight(2);
$lineplot7->SetColor("yellow");
$lineplot7->SetWeight(2);
$lineplot8->SetColor("blue");
$lineplot8->SetWeight(2);
$graph->yaxis->SetColor("red");
$graph->yaxis->SetWeight(2);
$graph->SetShadow();
$graph->Stroke();
?>
|
19.10.2012, 15:22:50
|
|
SELFPHP Guru
|
|
Registriert seit: Dec 2003
Ort: Erfurt
Alter: 75
Beiträge: 4.001
|
|
AW: Textdatei mittels JPGraph darstellen
Zitat:
Zitat von RubertIV
JpGraph Error: 25044 Cannot use auto scaling since it is impossible to determine a valid min/max value of the Y-axis (only null values).
Greif ich irgendwie auf ein falsches Array zu?
Hier noch mein Code:
PHP-Code:
<?php
$datei = file("Mappe1.txt");
|
Dir ist hoffentlich klar, daß file() nur ein explode("\n", $textstring) erledigt? Stammt Mappe1.txt aber von einem Windows Progrämmelchen, heißt das Zeilenende nicht "\n" sondern "\r\n".
Aus
PHP-Code:
"1;2;3\r\n4;5;6\r\n"
macht file()
PHP-Code:
$a = array("1;2;3\r", "4;5;6\r");
Das bedeutet:
3 !== "3\r"
Da Du die Arrayelemente noch mal mit explode(';'...) zerlegst, enthält das 3. Element keine Zahl sondern einen String, jpgraph will aber ne Zahl haben und nicht sowas, was so ähnlich wie eine Zahl aussieht.
Dem Gefrickel...
PHP-Code:
foreach($datei AS $ausgabe)
{
$x = explode(";", $ausgabe);
//fuege neue elemente zu den bestehenden arrays hinzu. array_push fuegt am ende ein
//tue das fuer jede zeile in $datei
array_push($Dates,$x[0]);
array_push($Times ,$x[1]);
array_push($Oberpegel ,$x[2]);
array_push($Unterpegel ,$x[3]);
array_push($Durchfluss ,$x[4]);
array_push($OS1 ,$x[5]);
array_push($US1 ,$x[6]);
array_push($OS2 ,$x[7]);
array_push($US2,$x[8]);
entnehme ich, daß Du dringend mal das Handbuch lesen solltest:
fgetcsv()
|
19.10.2012, 15:48:11
|
Anfänger
|
|
Registriert seit: Oct 2012
Alter: 37
Beiträge: 26
|
|
AW: Textdatei mittels JPGraph darstellen
danke erstmal für die schnelle antwort.
Aber kann ich noch nachträglich die arrays in zahlenarrays umwandeln?
|
19.10.2012, 17:59:42
|
|
SELFPHP Guru
|
|
Registriert seit: Dec 2003
Ort: Erfurt
Alter: 75
Beiträge: 4.001
|
|
AW: Textdatei mittels JPGraph darstellen
Zitat:
Zitat von RubertIV
Aber kann ich noch nachträglich die arrays in zahlenarrays umwandeln?
|
Machs doch gleich richtig:
entweder mit fgetcsv() (Handbuchlink kennste ja nun) - sehr komfortables arbeiten.
-> beachte aber das:
Zitat:
nick at atomicdesign dot net 13-Jan-2012 04:48
I was getting a bytes exhausted error when iterating through a CSV file.
PHP-Code:
ini_set('auto_detect_line_endings', 1);
fixed it.
|
Natürlich muß diese Einstellung schon gelten, bevor Du mit fgetcsv hantierst.
PHP-Code:
ini_set('auto_detect_line_endings', 1);
$a = array(); $b = array(); $c = array();
if (($handle = fopen("./pfad/dateiname", "r")) !== FALSE) { while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) { $num = count($data); if ($num < 1) # leer continue; $a[] = intval($data[0]); # sicherheitshalber $b[] = intval($data[1]); $c[] = intval($data[2]); } fclose($handle); } # weiter gehts mit jpgraph
oder so:
PHP-Code:
$temp = file_get_contents('pfad/dateiname'); $temp = str_replace("\r\n", "\n", $temp); $array = explode("\n", $temp);
Und weiter gehts dann mit Deinem "fgetcsv Ersatz".
|
22.10.2012, 10:57:39
|
Anfänger
|
|
Registriert seit: Oct 2012
Alter: 37
Beiträge: 26
|
|
AW: Textdatei mittels JPGraph darstellen
ok, ich versuchs mal
nun hattest du die werte als ganze zahlen ins array eingelesen:
$Oberpegel[] = intval($data[2]);
die änderte ich dann, weil ich auch die nachkomastellen benötige:
$Oberpegel[] = doubleval($data[2]);
jedoch bekomm ich aus dem array immer noch nur ganze zahlen, streicht der die nachkommawerte schon vorher irgendwo raus?
|
22.10.2012, 18:49:40
|
|
SELFPHP Guru
|
|
Registriert seit: Dec 2003
Ort: Erfurt
Alter: 75
Beiträge: 4.001
|
|
AW: Textdatei mittels JPGraph darstellen
Zitat:
Zitat von RubertIV
nun hattest du die werte als ganze zahlen ins array eingelesen:
|
Mehr, also in welcher Form die CSV Daten vorliegen, wußte ich ja nicht.
Wenn Du nicht mit Integer arbeitest und n Excel-CSV verwurstest, hast Du bezüglich des Zahlenformats einige Problem.
1. PHP kennt genaugenommen nur integer oder float.
2. bei float will PHP nen Dezimalpunkt und kein Komma. Und deshalb tritt floatval() da das fehlerhaftes Komma kommentarlos (falscher Errorlevel beim Entwickeln) in die Tonne. intval() machts ja auch: aus "1234blub" wird 1234.
jpgraph selber kenne ich nicht und weiß deshalb nicht, wie das Teil den Typ float serviert bekommen möchte. Da kannste aber selber mal im jpgraph Handbuch nachgucken.
|
23.10.2012, 08:37:20
|
Anfänger
|
|
Registriert seit: Oct 2012
Alter: 37
Beiträge: 26
|
|
AW: Textdatei mittels JPGraph darstellen
dann ändere ich mal die formatierung in excel
|
24.10.2012, 10:22:37
|
Anfänger
|
|
Registriert seit: Oct 2012
Alter: 37
Beiträge: 26
|
|
AW: Textdatei mittels JPGraph darstellen
ich bin jetzt so weit gekommen, dass keine fehler mehr angezeigt werden. Jedoch wird bei mir gar kein Bild angezeigt:
PHP-Code:
<?php
include ("jpgraph/src/jpgraph.php");
include ("jpgraph/src/jpgraph_line.php");
ini_set("auto_detect_line_endings",1);
$Datum = array();
$Times = array();
$Oberpegel = array();
$Unterpegel = array();
$Durchfluss = array();
$OS1 = array();
$US1 = array();
$OS2 = array();
$US2 = array();
$graph = new graph(1000,500,"auto");
$graph->SetScale("linlin");
if (($handle = fopen("Mappe1.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) {
$num = count($data);
if ($num < 1)
continue;
$Datum[] = floatval($data[0]);
$Times[] = floatval($data[1]);
$Oberpegel[] = floatval($data[2]);
$Unterpegel[] = floatval($data[3]);
$Durchfluss[] = floatval($data[4]);
$OS1[] = floatval($data[5]);
$US1[] = floatval($data[6]);
$OS2[] = floatval($data[7]);
$US2[] = floatval($data[8]);
}
fclose($handle);
}
print_r ($Oberpegel);
$lineplot1 = new lineplot($Oberpegel);
$lineplot2 = new lineplot($Unterpegel);
$lineplot3 = new lineplot($Durchfluss);
$lineplot4 = new lineplot($OS1);
$lineplot5 = new lineplot($US1);
$lineplot6 = new lineplot($OS2);
$lineplot7 = new lineplot($US2);
$graph->SetMargin(10,10,10,10);
$graph->SetMarginColor('white');
$graph->SetColor('lightgray');
$graph->Add($lineplot1);
$graph->Add($lineplot2);
$graph->Add($lineplot3);
$graph->Add($lineplot4);
$graph->Add($lineplot5);
$graph->Add($lineplot6);
$graph->Add($lineplot7);
// Grafik Formatieren
$graph->xaxis->title->Set("Time");
$graph->yaxis->title->Set("Y-title");
$graph->title->SetFont(FF_FONT1,FS_BOLD);
$graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD);
$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);
$lineplot1->SetColor("blue");
$lineplot1->SetWeight(2);
$lineplot2->SetColor("blue");
$lineplot2->SetWeight(2);
$lineplot3->SetColor("orange");
$lineplot3->SetWeight(2);
$lineplot4->SetColor("red");
$lineplot4->SetWeight(2);
$lineplot5->SetColor("black");
$lineplot5->SetWeight(2);
$lineplot6->SetColor("green");
$lineplot6->SetWeight(2);
$lineplot7->SetColor("yellow");
$lineplot7->SetWeight(2);
$graph->yaxis->SetColor("red");
$graph->yaxis->SetWeight(2);
$graph->SetShadow();
$graph->Stroke();
?>
ich sehe nur irgendwelche kryptischen zeichen:
IHDRèô!JzwIDATxœíÝlœw}ÀñÏÝ.”$…Ùùa:ÇUÜ‘+(†T¸]'¥ƒE*)JÿX,ú,•ø
ich habe auch schon so ein standard code von jpgraph ausprobiert, da funktionierte alles
Geändert von vt1816 (24.10.2012 um 13:38:51 Uhr)
Grund: Benutze bitte zukünftig die Foren-Tags!
|
24.10.2012, 14:53:51
|
Anfänger
|
|
Registriert seit: Oct 2012
Alter: 37
Beiträge: 26
|
|
AW: Textdatei mittels JPGraph darstellen
Es funzt!!!!!! XD
PHP-Code:
<?php
include ( "jpgraph/src/jpgraph.php");
include ("jpgraph/src/jpgraph_line.php");
$read = fopen('Mappe1.csv', 'r');
while ($data = fgetcsv($read, 1024, ';')) {
$Oberpegel[] = floatval($data[2]);
$Unterpegel[] = floatval($data[3]);
$Durchfluss[] = floatval($data[4]);
$OS1[] = floatval($data[5]);
$US1[] = floatval($data[6]);
$OS2[] = floatval($data[7]);
$US2[] = floatval($data[8]);
$xaxe[] = floatval($data[1]);
}
// Create the graph. These two calls are always required
$graph = new Graph(800, 800,"auto");
$graph->SetScale( "linlin");
$graph->SetY2Scale("lin");
//Beschriftung
$graph->img->SetMargin(40,40,20,40);
$graph->title->Set ('Verlauf');
$graph->xaxis-> title->Set("Datum" );
$graph->yaxis-> title->Set("Value" );
//Werte der x-Achse setzen
$graph->xaxis->SetTickLabels($xaxe);
// Create the linear plot
$lineplot =new LinePlot($Oberpegel);
$lineplot ->SetColor("blue");
$lineplot1 =new LinePlot($Unterpegel);
$lineplot1 ->SetColor("orange");
$lineplot2 =new LinePlot($Durchfluss);
$lineplot2 ->SetColor("green");
$lineplot3 =new LinePlot($OS1);
$lineplot3 ->SetColor("black");
$lineplot4 =new LinePlot($US1);
$lineplot4 ->SetColor("yellow");
$lineplot5 =new LinePlot($OS2);
$lineplot5 ->SetColor("red");
$lineplot6 =new LinePlot($US2);
$lineplot6 ->SetColor("orange");
// Add the plot to the graph
$graph->Add( $lineplot);
$graph->Add( $lineplot1);
$graph->AddY2( $lineplot2);
$graph->Add( $lineplot3);
$graph->Add( $lineplot4);
$graph->Add( $lineplot5);
$graph->Add( $lineplot6);
// Display the graph
$graph->Stroke();
?>
Herzlichsten Dank für die Hilfe meikel
|
24.10.2012, 18:29:53
|
|
SELFPHP Guru
|
|
Registriert seit: Dec 2003
Ort: Erfurt
Alter: 75
Beiträge: 4.001
|
|
AW: Textdatei mittels JPGraph darstellen
Zitat:
Zitat von RubertIV
Es funzt!!!!!! XD
...
Herzlichsten Dank für die Hilfe meikel
|
Danke für die Blumen. Und merke Dir meine Vorgehensweise. Ich könnte Dir Hinweise geben, obwohl ich von jpgraph keinen Dunst habe, wohl aber Schwach- und Stolperstellen bei Deiner Datenaufbereitung geahnt hatte. Schneller wäre es gegangen, wenn es paar Zeilen CSV gegeben hätte.
|
Aktive Benutzer in diesem Thema: 1 (Registrierte Benutzer: 0, Gäste: 1)
|
|
Forumregeln
|
Es ist Ihnen nicht erlaubt, neue Themen zu verfassen.
Es ist Ihnen nicht erlaubt, auf Beiträge zu antworten.
Es ist Ihnen nicht erlaubt, Anhänge hochzuladen.
Es ist Ihnen nicht erlaubt, Ihre Beiträge zu bearbeiten.
HTML-Code ist aus.
|
|
|
Alle Zeitangaben in WEZ +2. Es ist jetzt 08:35:54 Uhr.
|