Forum Moderators: phranque
<?php
$tempArr = array(
'42',
'39',
'37'
);
$windArr = array(
'40',
'37',
'35'
);
$rainArr = array(
'0',
'0',
'10
);
for ($i = 0; $i < count($tempArr); $i++) {
echo <<<EOF
<div style="float: left; margin-right: 5px">
<div style="float: left; width: 8%; height: {$tempArr[$i]}px; background: red"></div>
<div style="float: left; width: 8%; height: {$windArr[$i]}px; background: orange"></div>
<div style="float: left; width: 8%; height: {$rainArr[$i]}px; background: blue"></div>
</div>
EOF;
} <svg width="100%" height="100" style="background: #00AAAA">
<polyline points="0,37 20,39 40,41 60,45 80,44 100,43"
stroke="gold" stroke-width="3"
stroke-linecap="round" fill="none" stroke-linejoin="round" />
</svg> 1. How do I make it scaleable / responsive?
I don't understand "viewbox"
3. I don't understand ... "preserveAspectRatio" at all...
preserveAspectRatio="xMidYMid meet" 2. How can I make the color beneath the polyline change?
<polygon points="
0, 130
0, 110
598, 110
598, 130"
fill="#FFF" /> <svg viewBox="0 0 598 100" xmlns="http://www.w3.org/2000/svg">
<polygon points="
0, 100
0, 56
26, 55
...
598, 100"
stroke="yellow" stroke-width="0"
fill="#FFFFE0">
<title>Yup</title>
</polygon>
</svg> <style>
#container {
position: relative;
}
#tags {
display: flex;
align-items: stretch;
align-content: stretch;
overflow: hidden;
width: 100%;
position: absolute;
top: 0;
left: 0;
}
#tags div {
/* I'm struggling with the width because I need it to stay scalable. Setting it to 4.34x%works, but it's not perfect. I thought that align-items and align-content would make the DIVs fit by default, but it doesn't */
width: 4.34782608695652%;
height: 100%;
}
</style>
<div id="container">
<svg viewBox="0 0 598 100" xmlns="http://www.w3.org/2000/svg">
<polygon points="
0, 100
0, 56
26, 55
...
598, 100"
stroke="yellow" stroke-width="0"
fill="#FFFFE0">
<title>Yup</title>
</polygon>
</svg>
<div id="tags">
<div title="56"></div>
<div title="55"></div>
<div title="54"></div>
<div title="54"></div>
</div>
</div>
<script>
$('#tags').height($('svg').height());
</script>
<use href="url(#myDot)" x="20" y="30"><title>Yup!</title></use>
<use href="url(#myDot)" x="24" y="28"><title>Nope!</title></use>
.bars:hover #myID-1, .bars:hover #myID-2, .bars:hover #myID-3 {
display:block;
}
<svg viewBox="0 0 350.961538462 115" xmlns="http://www.w3.org/2000/svg">
<polygon points="
0, 115
0, 24.8113207547
14.0384615385, 21.0377358491
...
350.961538462, 35.7547169811
350.961538462, 115"
id="lines"
fill="#E6F2FA" />
<polyline points="
0, 24.8113207547
14.0384615385, 21.0377358491
...
350.961538462, 35.7547169811"
stroke="#B5D9F0" stroke-width="1"
stroke-linecap="round" fill="none" stroke-linejoin="round" />
<!-- I'm matching X and Y to the X and Y of the respective points -->
<!-- width is 365 / number of segments, height is the max height of the SVG -->
<use href="#lines" x="0" y="24.8113207547" width="14.0384615385" height="115">
<title>$2.39, Friday, Mar 8, 2019</title>
</use>
<use href="#lines" x="14.0384615385" y="21.0377358491" width="14.0384615385" height="115">
<title>$2.49, Tuesday, Apr 2, 2019</title>
</use>
...
<use href="#lines" x="350.961538462" y="35.7547169811" width="14.0384615385" height="115">
<title>$2.10, Thursday, Jan 30, 2020</title>
</use>
</svg>