I have two values that I take from an array:
$target = $data->data[2][32][3];
In this case $target = 9.83%
.
$clicks = $data->data[1][32][3];
In this case $clicks = 7.15%
.
I have a barlike chart made from an .outer div
(which represents the background div, the div which contains all the others), an .inner div
(which fills the outer...you can think of it like a bar that shows the percentage completed) and a .target div
(which represents the dotted line/ the target that the .inner div must reach..in some cases like this one it exceeds the target: .inner > .target
).
$target = 9.83%;
$bar_width = '200px';
$clicks = 7.15%;
$base = max($target, $clicks);
.outer,
.inner,
.target {
height: 14px;
margin-bottom: 5px;
}
.outer {
background-color: #cccccc;
width: 200px;
margin: 20px auto;
position: relative;
font-size: 10px;
line-height: 14px;
font-family: sans-serif;
}
.inner {
background-color: green;
position: absolute;
z-index: 1;
text-align: right;
width: calc(200 / 100 * <?php echo $base; ?>);
border-right: 2px solid black;
}
.inner:after {
content: ' 7.15%';
display: inline-block;
left: 10px;
position: relative;
height: 100%;
top: -14px;
margin-left: 17px;
}
.target {
background-color: transparent;
width: 19px;
position: absolute;
z-index: 2;
color: black;
text-align: right;
border-right: 2px dotted black;
}
.target:after {
content: 'Target: 9.83%';
display: inline-block;
left: 28px;
position: relative;
height: 100%;
top: 14px;
margin-left: -60px;
}
<div class="outer">
<div class="target" style="width: calc(<?php echo $bar_width; ?> / 100 * (<?php echo $target; ?> / <?php echo $base; ?> * 100))">
</div>
<div class="inner" style=" width: calc(<?php echo $bar_width; ?> / 100 * (<?php echo $clicks; ?> / <?php echo $base; ?> * 100))">
</div>
</div>
So my problem is that after the target is exceeded the inner div should completely fill the outer div.
</div>