/** * Get an instance of a SparklineLine object, always creating it * * @param array Configuration array * @return object KChartSparklineBar proxy object */ public static function getInstance($config = array()) { if (!isset($config['catch_errors'])) { $config['catch_errors'] = true; } $obj = new Sparkline_Line($config['catch_errors']); $obj->SetDebugLevel(DEBUG_NONE); return new KChartSparklineLine($obj); }
public static function paintPolitico($id) { $c = new Criteria(); $c->add(SfReviewTypeEntityPeer::ENTITY_ID, $id); $c->add(SfReviewTypeEntityPeer::VALUE, 1); $c->addAscendingOrderByColumn(SfReviewTypeEntityPeer::DATE); $elements = SfReviewTypeEntityPeer::doSelect($c); $sparkline = new Sparkline_Line(); $sparkline->SetDebugLevel(DEBUG_NONE); $sparkline->SetColorHtml('background', '#e0e0e0'); $sparkline->SetColorBackground('background'); $i = 0; foreach ($elements as $element) { $i++; $sparkline->SetData($i, $element->getSum()); } $sparkline->SetYMin(0); $sparkline->SetLineSize(4); $sparkline->RenderResampled(100, 15); $sparkline->Output(); }
function main() { $width = self::getWidth(); $height = self::getHeight(); $data = $this->values; $sparkline = new Sparkline_Line(); $sparkline->SetColor('lineColor', 22, 44, 74); // dark blue $sparkline->SetColorHtml('red', '#FF7F7F'); $sparkline->SetColorHtml('blue', '#55AAFF'); $sparkline->SetColorHtml('green', '#75BF7C'); $data = array_reverse($data); $min = $max = $last = null; $i = 0; foreach ($this->values as $value) { $sparkline->SetData($i, $value); if (null == $min || $value <= $min[1]) { $min = array($i, $value); } if (null == $max || $value >= $max[1]) { $max = array($i, $value); } $last = array($i, $value); $i++; } $sparkline->SetYMin(0); $sparkline->setYMax($max[1] + 0.5); // the +0.5 seems to be mandatory to not lose some pixels when value = max $sparkline->SetPadding(3, 0, 2, 0); $font = FONT_2; // the -0.5 is a hack as the sparkline samping rendering is obviously slightly bugged // (see also fix marked as //FIX FROM PIWIK in libs/sparkline/lib/Sparkline.php) $sparkline->SetFeaturePoint($min[0] - 1, $min[1], 'red', 5); $sparkline->SetFeaturePoint($max[0] - 1, $max[1], 'green', 5); $sparkline->SetFeaturePoint($last[0] - 1, $last[1], 'blue', 5); $sparkline->SetLineSize(3); // for renderresampled, linesize is on virtual image $ratio = 1; // var_dump($min);var_dump($max);var_dump($lasts);exit; $sparkline->RenderResampled($width * $ratio, $height * $ratio); $this->sparkline = $sparkline; }
function main() { $width = self::getWidth(); $height = self::getHeight(); $sparkline = new Sparkline_Line(); $sparkline->SetColor('lineColor', 22, 44, 74); // dark blue $sparkline->SetColorHtml('red', '#FF7F7F'); $sparkline->SetColorHtml('blue', '#55AAFF'); $sparkline->SetColorHtml('green', '#75BF7C'); $min = $max = $last = null; $i = 0; foreach ($this->values as $value) { // 50% and 50s should be plotted as 50 $toRemove = array('%', 's'); $value = str_replace($toRemove, '', $value); // replace localized decimal separator $value = str_replace(',', '.', $value); if ($value == '') { $value = 0; } $sparkline->SetData($i, $value); if (null == $min || $value <= $min[1]) { $min = array($i, $value); } if (null == $max || $value >= $max[1]) { $max = array($i, $value); } $last = array($i, $value); $i++; } $sparkline->SetYMin(0); $sparkline->SetYMax($max[1]); $sparkline->SetPadding(3, 0, 2, 0); // top, right, bottom, left // $font = FONT_2; $sparkline->SetFeaturePoint($min[0], $min[1], 'red', 5); $sparkline->SetFeaturePoint($max[0], $max[1], 'green', 5); $sparkline->SetFeaturePoint($last[0], $last[1], 'blue', 5); $sparkline->SetLineSize(3); // for renderresampled, linesize is on virtual image $ratio = 1; // var_dump($min);var_dump($max);var_dump($lasts);exit; $sparkline->RenderResampled($width * $ratio, $height * $ratio); $this->sparkline = $sparkline; }
$query_var = $_GET["q"]; $values = explode(",", $query_var); $graphType = strtoupper($_GET['type']); if ($graphType == '') { $graphType = 'BAR'; } $is_odd = $_GET['odd']; $graphColor = $_GET['color']; $bar_width = $_GET['bw']; if ($bar_width == '') { $bar_width = 1; } $isDebug = $_GET["debug"] == 1; if ($graphType == 'LINE') { require_once dirname(__FILE__) . '/lib/Sparkline_Line.php'; $sparkline = new Sparkline_Line(); if ($isDebug) { $sparkline->SetDebugLevel(DEBUG_ERROR | DEBUG_WARNING | DEBUG_STATS | DEBUG_CALLS | DEBUG_SET, 'log.txt'); } else { $sparkline->SetDebugLevel(DEBUG_NONE); } if ($is_odd) { $sparkline->SetColorHtml('mintOdd', '#F0F7E2'); $sparkline->SetColorBackground('mintOdd'); } else { $sparkline->SetColorBackground('white'); } $sparkline->SetYMin(0); $sparkline->SetPadding(0); $sparkline->SetColorHtml("sparkLine", $graphColor); $j = 0;
<?php include "util.inc"; $moteid = $_GET['m']; $name = $_GET['n']; if (isset($_GET['t'])) { $text = true; } require_once 'sparkline/Sparkline_Line.php'; $sparkline = new Sparkline_Line(); $sparkline->SetDebugLevel(DEBUG_NONE); //$sparkline->SetDebugLevel(DEBUG_ERROR | DEBUG_WARNING | DEBUG_STATS | DEBUG_CALLS | DEBUG_DRAW | DEBUG_SET, '../log2.txt'); $x = 0; foreach ($_SESSION['query']['data'][$moteid] as $responseTime => $theName) { $value = $_SESSION['query']['data'][$moteid][$responseTime][$name]; if (isset($lastValue) && $value != $lastValue) { $hasChange = true; } if (!isset($baseTime)) { $baseTime = $responseTime; } $scaledTime = $responseTime - $baseTime; $scaledTime = $x; if ($text) { print "{$scaledTime} - {$value}<br>"; } else { $sparkline->SetData($scaledTime, $value); } $x += 1; $lastValue = $value; }
// data sample: // 0 1 2 3 4 5 6 // Date,Open,High,Low,Close,Volume,Adj. Close* // 5-Nov-04,29.21,29.36,29.03,29.31,95337696,29.31 // $url = "http://ichart.finance.yahoo.com/table.csv?s=" . $_GET['s'] . "&a={$m}&b={$d}&c={$y1}&d={$m}&e={$d}&f={$y2}&g=d&ignore=.csv"; if (!($data = @file($url))) { die('error fetching stock data; verify ticker symbol'); } ////////////////////////////////////////////////////////////////////////////// // build sparkline using standard flow: // construct, set, render, output // header('Content-type: image/png'); require_once 'Sparkline_Line.php'; $sparkline = new Sparkline_Line(); $sparkline->SetDebugLevel(DEBUG_NONE); //$sparkline->SetDebugLevel(DEBUG_ERROR | DEBUG_WARNING | DEBUG_STATS | DEBUG_CALLS, '../log.txt'); if (isset($_GET['b'])) { $sparkline->SetColorHtml('background', $_GET['b']); $sparkline->SetColorBackground('background'); } $data = array_reverse($data); $i = 0; while (list(, $v) = each($data)) { $elements = explode(',', $v); if (ereg('^[0-9\\.]+$', trim($elements[6]))) { $sparkline->SetData($i, $elements[6]); $i++; } }
function main() { $data = $this->data; $sparkline = new Sparkline_Line(); $sparkline->SetColor('lineColor', 22, 44, 74); // dark blue $sparkline->SetColorHtml('red', '#FF7F7F'); $sparkline->SetColorHtml('blue', '#55AAFF'); $sparkline->SetColorHtml('green', '#75BF7C'); // $sparkline->SetDebugLevel(DEBUG_NONE); // $sparkline->SetDebugLevel(DEBUG_ERROR | DEBUG_WARNING | DEBUG_STATS | DEBUG_CALLS | DEBUG_DRAW, 'log.txt'); $data = array_reverse($data); $min = $max = $last = null; $i = 0; foreach ($this->data as $row) { $value = $row['value']; $sparkline->SetData($i, $value); if (null == $min || $value <= $min[1]) { $min = array($i, $value); } if (null == $max || $value >= $max[1]) { $max = array($i, $value); } $last = array($i, $value); $i++; } $sparkline->SetYMin(0); $sparkline->SetPadding(2); // setpadding is additive $sparkline->SetPadding(0, 3, 0, 0); $font = FONT_2; $sparkline->SetFeaturePoint($min[0] - 1, $min[1], 'red', 5); $sparkline->SetFeaturePoint($max[0] - 1, $max[1], 'green', 5); $sparkline->SetFeaturePoint($last[0] - 1, $last[1], 'blue', 5); $sparkline->SetLineSize(3); // for renderresampled, linesize is on virtual image $sparkline->RenderResampled(100, 20, 'lineColor'); $this->sparkline = $sparkline; }
function main() { $width = self::getWidth(); $height = self::getHeight(); $data = $this->values; $sparkline = new Sparkline_Line(); $sparkline->SetColor('lineColor', 22, 44, 74); // dark blue $sparkline->SetColorHtml('red', '#FF7F7F'); $sparkline->SetColorHtml('blue', '#55AAFF'); $sparkline->SetColorHtml('green', '#75BF7C'); $data = array_reverse($data); $min = $max = $last = null; $i = 0; foreach ($this->values as $value) { $sparkline->SetData($i, $value); if (null == $min || $value <= $min[1]) { $min = array($i, $value); } if (null == $max || $value >= $max[1]) { $max = array($i, $value); } $last = array($i, $value); $i++; } $sparkline->SetYMin(0); $sparkline->SetYMax($max[1]); $sparkline->SetPadding(3, 0, 2, 0); // top, right, bottom, left // $font = FONT_2; $sparkline->SetFeaturePoint($min[0] - 1, $min[1], 'red', 5); $sparkline->SetFeaturePoint($max[0] - 1, $max[1], 'green', 5); $sparkline->SetFeaturePoint($last[0] - 1, $last[1], 'blue', 5); $sparkline->SetLineSize(3); // for renderresampled, linesize is on virtual image $ratio = 1; // var_dump($min);var_dump($max);var_dump($lasts);exit; $sparkline->RenderResampled($width * $ratio, $height * $ratio); $this->sparkline = $sparkline; }