Created
November 28, 2012 16:54
-
-
Save markbalt/4162498 to your computer and use it in GitHub Desktop.
Create a simple CSS bar graph in View (for visits in the past 14 days)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php for ($i=14;$i>0;$i--) : ?> | |
<span class="graph"> | |
<?php | |
$date = new DateTime(); | |
$date->sub(new DateInterval("P".$i."D")); | |
$start = new DateTime($date->format('Y-m-d 00:00:00')); | |
$end = new DateTime($date->format('Y-m-d 23:59:59')); | |
$y = $visitLocation->getVisitsInRange($start, $end); | |
$nextday = new DateTime($date->format('Y-m-d 00:00:00')); | |
$nextday->add(new DateInterval("P1D")); | |
if ($y != 0) { | |
$percent = round($y/25*100, 2); | |
} else { | |
$percent = 0; | |
} | |
if ($percent > 100) { | |
$percent = 100; | |
} | |
?> | |
<a href="<?php echo url_for('visit/filter').'?visit_filters[location_id]='.$visitLocation->getId().'&visit_filters[arrival_date][from]='.$start->format('Y-m-d').'&visit_filters[arrival_date][to]='.$nextday->format('Y-m-d'); ?>" class="fill" style="height: <?php echo $percent; ?>%;" title="<?php echo $y ?> visits <?php echo $start->format('l, M j'); ?>"><?php echo $y ?> visits <?php echo $start->format('l, M j'); ?></a> | |
</span> | |
<?php endfor; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The link filters the visits by that time span.