function display_chart($data) { //echo "data : "; var_dump($data); echo "<br />"; $i = 0; foreach ($data as $abs => $val) { //echo "$abs => $val <br />"; $abscissa[$i] = $abs; //$arr[month_to_string($res[0])] = $res[1]; $i++; } $maxval = max($data); $chart = new GoogleChart('lc', 600, 300); $chart->setScale(0, $maxval); $line = new GoogleChartData($data); $chart->addData($line); $y_axis = new GoogleChartAxis('y'); $y_axis->setDrawTickMarks(false); $y_axis->setRange(0, $maxval); // $y_axis->setLabels(array(0,10,20,30)); $chart->addAxis($y_axis); $x_axis = new GoogleChartAxis('x'); $x_axis->setTickMarks(5); $x_axis->setLabels($abscissa); $chart->addAxis($x_axis); // add a shape marker with a border $shape_marker = new GoogleChartShapeMarker(GoogleChartShapeMarker::CIRCLE); $shape_marker->setSize(6); $shape_marker->setBorder(2); $shape_marker->setData($line); $chart->addMarker($shape_marker); // add a value marker $value_marker = new GoogleChartTextMarker(GoogleChartTextMarker::VALUE); $value_marker->setData($line); $chart->addMarker($value_marker); // var_dump($chart->getQuery()); // echo $chart->validate(); echo $chart->toHtml(); }
static function renderChart(&$params) { // get data $db = JFactory::getDBO(); $value_data = array(); $history = intval($params->get('history', 7)); // currently active users $query = 'select count(tdate) as unique_visitors, tdate from (SELECT date(timestamp) as tdate from #__rokuserstats WHERE timestamp >= date_sub(curdate(),interval ' . $history . ' day) group by ip, user_id, tdate order by tdate) as foo group by tdate'; $db->setQuery($query); $data = $db->loadObjectList(); if (is_array($data)) { foreach ($data as $row) { $value_data[] = $row->unique_visitors; } } if (empty($value_data)) { $value_data[] = 0; } $max = max($value_data); require_once 'googlechartlib/GoogleChart.php'; $chart = new GoogleChart('lc', $params->get('width', 285), $params->get('height', 120)); $chart->setTitle(JTEXT::sprintf('MC_RUC_TITLE', intval($history))); $chart->setTitleColor('666666')->setTitleSize(13); $data = new GoogleChartData($value_data); $data->setColor('4F9BD8'); $data->setThickness(2); $chart->addData($data); $y_axis = new GoogleChartAxis('y'); $y_axis->setRange(0, $max); $y_axis->setTickMarks(2); $x_axis = new GoogleChartAxis('x'); $x_axis->setRange(0, count($value_data) - 1); $x_axis->setTickMarks(2); $chart->addAxis($y_axis); $chart->addAxis($x_axis); return $chart->toHtml(); }
// see http://code.google.com/p/googlechartphplib/wiki/GettingStarted //################################################################################# // don't forget to update the path here require './lib/GoogleChart.php'; $chart = new GoogleChart('lc', 500, 200); // manually forcing the scale to [0,100] $chart->setScale(0, 100); // add one line $data = new GoogleChartData(array(49, 74, 78, 71, 40, 39, 35, 20, 50, 61, 45)); $chart->addData($data); // customize y axis $y_axis = new GoogleChartAxis('y'); $y_axis->setDrawTickMarks(false)->setLabels(array(0, 50, 100)); $chart->addAxis($y_axis); // customize x axis $x_axis = new GoogleChartAxis('x'); $x_axis->setTickMarks(5); $chart->addAxis($x_axis); echo $chart->toHtml(); //################################################################################# // END //################################################################################# // see http://sidu.sourceforge.net/chart/example-k.php echo "<p>"; echo "<img src='bChart.php?data=id,color;A,1.5;B,2;C,3;D,4;" . "E,3;F,2;G,1;H,2;I,3;J,4;K,3;L,2;M,1;N,2;O,3;P,4;Q,3;" . "R,2;S,3;T,2;U,1;V,2;W,3;X,5" . "&legend=1'>"; echo "</p>"; //################################################################################# echo "<p>v0.92" . "</body>" . "</html>"; ?>