Feldwert aus einer externen XML Datei mit PHP in ein SVG Diagramm übertragen
Guten Tag,
ich möchte aus einer XML Datei ein bestimmtes Feld auslesen und nur einen Wert
in ein SVG Diagramm übertragen.
Ich habe mal Testweise die XML Datei von http://www.pegelonline.wsv.de/svgz/pegelstaende_neu.xml
genommen.
Hier mal mein PHP Code dazu Wert '223' wird ausgegeben:
Nun möchte ich diesen wert in dieses SVG Balkendiagramm übertragen:
Wie könnte ich das umsetzen?
Vielen Dank
ich möchte aus einer XML Datei ein bestimmtes Feld auslesen und nur einen Wert
in ein SVG Diagramm übertragen.
Ich habe mal Testweise die XML Datei von http://www.pegelonline.wsv.de/svgz/pegelstaende_neu.xml
genommen.
Hier mal mein PHP Code dazu Wert '223' wird ausgegeben:
<?php
$out = '';
function _PRS($str) {
return(iconv("UTF-8","ISO-8859-1//TRANSLIT",$str));
}
try {
$xref = simplexml_load_file('http://www.pegelonline.wsv.de/svgz/pegelstaende_neu.xml');
foreach ($xref->table->gewaesser as $value) {
if (_PRS($value->name) == 'ELBE') {
foreach ($value->item as $items) {
if (_PRS($items->pegelname) == 'DRESDEN') {
$out .= ""._PRS($items->messwert)."";
break;
}
}
break;
}
}
if ($out == '') {
$out = "No Data";
}
} catch (Exception $e) {
$out = "No Data";
}
echo($out);
?>
Nun möchte ich diesen wert in dieses SVG Balkendiagramm übertragen:
<svg width="650" height="500">
<g id="axis" transform="translate(0 500) scale(1 -1)">
<line id="axis-y" x1="30" y1="20" x2="30" y2="450" style="fill:none;stroke:rgb(0,0,0);stroke-width:2"/>
<line id="axis-x" x1="30" y1="20" x2="460" y2="20" style="fill:none;stroke:rgb(0,0,0);stroke-width:2"/>
</g>
<g id="bars" transform="translate(30 479) scale(1 -430)">
<rect x="30" y="0" width="50" height=$out .= ""._PRS($items->messwert).""; style="fill:rgb(255,0,0);stroke:rgb(0,0,0);stroke-width:0"/>
<rect x="100" y="0" width="50" height="HIER SOLL DIE 223 EINGEFÜGT WERDEN" style="fill:rgb(0,255,0);stroke:rgb(0,0,0);stroke-width:0"/>
<rect x="170" y="0" width="50" height="0.75" style="fill:rgb(255,255,0);stroke:rgb(0,0,0);stroke-width:0"/>
<rect x="240" y="0" width="50" height="0.9" style="fill:rgb(0,255,255);stroke:rgb(0,0,0);stroke-width:0"/>
<rect x="310" y="0" width="50" height="1" style="fill:rgb(0,0,255);stroke:rgb(0,0,0);stroke-width:0"/>
</g>
<g id="scale" transform="translate(29 60)">
<text id="scale1" x="0px" y="320px" style="text-anchor:end;fill:rgb(0,0,0);font-size:10;font-family:Arial">0.25</text>
<text id="scale2" x="0px" y="215px" style="text-anchor:end;fill:rgb(0,0,0);font-size:10;font-family:Arial">0.50</text>
<text id="scale3" x="0px" y="107.5px" style="text-anchor:end;fill:rgb(0,0,0);font-size:10;font-family:Arial">0.75</text>
<text id="scale4" x="0px" y="0px" style="text-anchor:end;fill:rgb(0,0,0);font-size:10;font-family:Arial">1.00</text>
</g>
<g id="key">
<rect id="key1" x="430" y="80" width="25" height="15" style="fill:rgb(255,0,0);stroke:rgb(0,0,0);stroke-width:1"/>
<rect id="key2" x="430" y="100" width="25" height="15" style="fill:rgb(0,255,0);stroke:rgb(0,0,0);stroke-width:1"/>
<rect id="key3" x="430" y="120" width="25" height="15" style="fill:rgb(255,255,0);stroke:rgb(0,0,0);stroke-width:1"/>
<rect id="key5" x="430" y="140" width="25" height="15" style="fill:rgb(0,255,255);stroke:rgb(0,0,0);stroke-width:1"/>
<rect id="key4" x="430" y="160" width="25" height="15" style="fill:rgb(0,0,255);stroke:rgb(0,0,0);stroke-width:1"/>
<text id="key1-text" x="465px" y="92px" style="fill:rgb(0,0,0);font-size:18;font-family:Arial">schlüssel1</text>
<text id="key2-text" x="465px" y="112px" style="fill:rgb(0,0,0);font-size:18;font-family:Arial">schlüssel2</text>
<text id="key3-text" x="465px" y="132px" style="fill:rgb(0,0,0);font-size:18;font-family:Arial">schlüssel3</text>
<text id="key4-text" x="465px" y="152px" style="fill:rgb(0,0,0);font-size:18;font-family:Arial">schlüssel4</text>
<text id="key5-text" x="465px" y="172px" style="fill:rgb(0,0,0);font-size:18;font-family:Arial">schlüssel5</text>
</g>
<g id="title">
<text x="325px" y="20px" style="text-anchor:middle;fill:rgb(0,0,0);font-size:24;font-family:Arial">Überschrift</text>
</g>
</svg>
Wie könnte ich das umsetzen?
Vielen Dank
Please also mark the comments that contributed to the solution of the article
Content-Key: 356619
Url: https://administrator.de/contentid/356619
Printed on: April 18, 2024 at 10:04 o'clock
4 Comments
Latest comment
HIER SOLL DIE 223 EINGEFÜGT WERDEN
Und warum fügst du dann dort nicht die Variable $out ein??
Naja das muss natürlich so aussehen:
Da du ja nicht mehr im PHP Kontext sondern im HTML-Kontext bist , deswegen musst du dort erst wieder rein wechseln.
height="<?php echo $out;?>"