Skip to content

Instantly share code, notes, and snippets.

@markbalt
Created November 28, 2012 16:54
Show Gist options
  • Save markbalt/4162498 to your computer and use it in GitHub Desktop.
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)
<?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; ?>
@markbalt
Copy link
Author

The link filters the visits by that time span.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment