Exemple #1
0
 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();
 }
Exemple #2
0
/**
 * Draws Chart for PDF Report.
 *
 * Draws the sales and earnings chart for the PDF report and then retrieves the
 * URL of that chart to display on the PDF Report.
 *
 * @since  1.1.4.0
 * @uses   GoogleChart
 * @uses   GoogleChartData
 * @uses   GoogleChartShapeMarker
 * @uses   GoogleChartTextMarker
 * @uses   GoogleChartAxis
 * @return string $chart->getUrl() URL for the Google Chart
 */
function give_draw_chart_image()
{
    require_once GIVE_PLUGIN_DIR . '/includes/libraries/googlechartlib/GoogleChart.php';
    require_once GIVE_PLUGIN_DIR . '/includes/libraries/googlechartlib/markers/GoogleChartShapeMarker.php';
    require_once GIVE_PLUGIN_DIR . '/includes/libraries/googlechartlib/markers/GoogleChartTextMarker.php';
    $chart = new GoogleChart('lc', 900, 330);
    $i = 1;
    $earnings = "";
    $sales = "";
    while ($i <= 12) {
        $earnings .= give_get_earnings_by_date(null, $i, date('Y')) . ",";
        $sales .= give_get_sales_by_date(null, $i, date('Y')) . ",";
        $i++;
    }
    $earnings_array = explode(",", $earnings);
    $sales_array = explode(",", $sales);
    $i = 0;
    while ($i <= 11) {
        if (empty($sales_array[$i])) {
            $sales_array[$i] = 0;
        }
        $i++;
    }
    $min_earnings = 0;
    $max_earnings = max($earnings_array);
    $earnings_scale = round($max_earnings, -1);
    $data = new GoogleChartData(array($earnings_array[0], $earnings_array[1], $earnings_array[2], $earnings_array[3], $earnings_array[4], $earnings_array[5], $earnings_array[6], $earnings_array[7], $earnings_array[8], $earnings_array[9], $earnings_array[10], $earnings_array[11]));
    $data->setLegend(esc_html__('Income', 'give'));
    $data->setColor('1b58a3');
    $chart->addData($data);
    $shape_marker = new GoogleChartShapeMarker(GoogleChartShapeMarker::CIRCLE);
    $shape_marker->setColor('000000');
    $shape_marker->setSize(7);
    $shape_marker->setBorder(2);
    $shape_marker->setData($data);
    $chart->addMarker($shape_marker);
    $value_marker = new GoogleChartTextMarker(GoogleChartTextMarker::VALUE);
    $value_marker->setColor('000000');
    $value_marker->setData($data);
    $chart->addMarker($value_marker);
    $data = new GoogleChartData(array($sales_array[0], $sales_array[1], $sales_array[2], $sales_array[3], $sales_array[4], $sales_array[5], $sales_array[6], $sales_array[7], $sales_array[8], $sales_array[9], $sales_array[10], $sales_array[11]));
    $data->setLegend(esc_html__('Donations', 'give'));
    $data->setColor('ff6c1c');
    $chart->addData($data);
    $chart->setTitle(esc_html__('Donations by Month for all Give Forms', 'give'), '336699', 18);
    $chart->setScale(0, $max_earnings);
    $y_axis = new GoogleChartAxis('y');
    $y_axis->setDrawTickMarks(true)->setLabels(array(0, $max_earnings));
    $chart->addAxis($y_axis);
    $x_axis = new GoogleChartAxis('x');
    $x_axis->setTickMarks(5);
    $x_axis->setLabels(array(esc_html__('Jan', 'give'), esc_html__('Feb', 'give'), esc_html__('Mar', 'give'), esc_html__('Apr', 'give'), esc_html__('May', 'give'), esc_html__('June', 'give'), esc_html__('July', 'give'), esc_html__('Aug', 'give'), esc_html__('Sept', 'give'), esc_html__('Oct', 'give'), esc_html__('Nov', 'give'), esc_html__('Dec', 'give')));
    $chart->addAxis($x_axis);
    $shape_marker = new GoogleChartShapeMarker(GoogleChartShapeMarker::CIRCLE);
    $shape_marker->setSize(6);
    $shape_marker->setBorder(2);
    $shape_marker->setData($data);
    $chart->addMarker($shape_marker);
    $value_marker = new GoogleChartTextMarker(GoogleChartTextMarker::VALUE);
    $value_marker->setData($data);
    $chart->addMarker($value_marker);
    return $chart->getUrl();
}
Exemple #3
0
<?php

require '../lib/GooglePieChart.php';
$chart = new GooglePieChart('p', 130, 100);
$chart->setDataFormat(GoogleChart::SIMPLE_ENCODING);
$data = new GoogleChartData(array(80, -20));
$data->setColor('f9f900');
$chart->addData($data);
// I pass null to enable the "legend" trick
$data = new GoogleChartData(null);
$data->setColor('ffffff');
$data->setLegend('O O O');
$chart->addData($data);
$chart->setLegendPosition('r');
$chart->setRotation(0.628);
if (isset($_GET['debug'])) {
    var_dump($chart->getQuery());
    echo $chart->validate();
    echo $chart->toHtml();
} else {
    header('Content-Type: image/png');
    echo $chart;
}
$chart = new GoogleChart('lc', 180, 150);
$data = new GoogleChartData(array(10, 15, 25, 30, 45, 55, 58));
$data->setLegend('Foobar');
$chart->addData($data);
// no legend for this data serie
$data = new GoogleChartData(array(5, 12, 28, 26, 30, 34, 32));
$data->setColor('FF0000');
$chart->addData($data);
echo $chart->toHtml();
$chart = new GoogleChart('lc', 180, 150);
$chart->setLegendPosition('b');
$data = new GoogleChartData(array(10, 15, 25, 30, 45, 55, 58));
$data->setLegend('Foo');
$chart->addData($data);
$data = new GoogleChartData(array(5, 12, 28, 26, 30, 34, 32));
$data->setLegend('Bar');
$data->setColor('FF0000');
$chart->addData($data);
echo $chart->toHtml();
$chart = new GoogleChart('lc', 180, 150);
$chart->setLegendPosition('t');
$chart->setLegendSize(18);
$chart->setLegendColor('336699');
$data = new GoogleChartData(array(10, 15, 25, 30, 45, 55, 58));
$data->setLegend('Foo');
$chart->addData($data);
$data = new GoogleChartData(array(5, 12, 28, 26, 30, 34, 32));
$data->setLegend('Bar');
$data->setColor('FF0000');
$chart->addData($data);
echo $chart->toHtml();
Exemple #5
0
$line = new GoogleChartData($values);
$line->setColor('000000');
$line->setThickness(3);
$line->setFill('eeeeee');
$chart->addData($line);
$m = new GoogleChartShapeMarker(GoogleChartShapeMarker::CIRCLE);
$m->setData($line);
$m->setColor('000000');
$m->setSize(7);
$m->setBorder(2);
$chart->addMarker($m);
$values = array_fill(0, sizeof($values) - 2, null);
$values[] = 44;
$values[] = 34;
$line2 = new GoogleChartData($values);
$line2->setColor('000000');
$line2->setThickness(3);
$line2->setDash(4, 2);
$line2->setFill('eeeeee');
$chart->addData($line2);
$m = new GoogleChartShapeMarker(GoogleChartShapeMarker::CIRCLE);
$m->setData($line2);
$m->setColor('ffffff');
$m->setSize(4);
$m->setBorder(4, '000000');
$m->setPoints(-1);
$chart->addMarker($m);
$y_axis = new GoogleChartAxis('y');
$y_axis->setDrawLine(false);
$y_axis->setDrawTickMarks(false);
$y_axis->setLabels(array(null, 35, 70));
require '../../lib/GoogleBarChart.php';
?>

<h2>Data autoscaling (text format)</h2>
<?php 
$values1 = array(-10, 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110);
$values2 = array(10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130);
$chart = new GoogleBarChart('bvg', 500, 200);
$chart->setDataFormat(GoogleChart::TEXT);
$chart->setAutoscale(GoogleChart::AUTOSCALE_OFF);
$data = new GoogleChartData($values1);
$data->setAutoscale(true);
$chart->addData($data);
$data = new GoogleChartData($values2);
$data->setColor('336699');
$data->setAutoscale(true);
$chart->addData($data);
$y_axis = new GoogleChartAxis('y');
$chart->addAxis($y_axis);
echo $chart->toHtml();
var_dump($chart->getQuery());
?>

<h2>Data autoscaling (simple encoding)</h2>
<?php 
$chart->setDataFormat(GoogleChart::SIMPLE_ENCODING);
echo $chart->toHtml();
var_dump($chart->getQuery());
?>
$chart->setMargin(30, 50);
$chart->setLegendSize(100, 10);
$chart->setFill('333333');
$chart->setFill('444444', GoogleChart::CHART_AREA);
$chart->setTitle('Sinus & Cosinus');
$chart->setTitleColor('FFFFFF');
$chart->setTitleSize(18);
$sin = new GoogleChartData($sin);
$sin->setLegend('Sinus');
$sin->setThickness(2);
$sin->setColor('D1F2A5');
$chart->addData($sin);
$cos = new GoogleChartData($cos);
$cos->setLegend('Cosinus');
$cos->setThickness(2);
$cos->setColor('F56991');
$chart->addData($cos);
$y_axis = new GoogleChartAxis('y');
$y_axis->setDrawLine(false);
$y_axis->setRange(-1, 1);
$y_axis->setLabelColor('ffffff');
$chart->addAxis($y_axis);
$x_axis = new GoogleChartAxis('x');
$x_axis->setDrawLine(false);
$x_axis->setRange(0, 360);
$x_axis->setLabels(array(0, 90, 180, 270, 360));
$x_axis->setLabelColor('ffffff');
$chart->addAxis($x_axis);
if (isset($_GET['debug'])) {
    var_dump($chart->getQuery());
    echo $chart->validate();
require '../lib/GoogleChart.php';
require '../lib/markers/GoogleChartLineMarker.php';
require '../lib/markers/GoogleChartShapeMarker.php';
$values = array(array(), array(), array());
for ($i = 0; $i <= 10; $i += 1) {
    $v = rand(20, 80);
    $values[0][] = $v;
    $values[1][] = rand(0, 20);
    $values[2][] = $v + rand(-10, 10);
}
$chart = new GoogleChart('bvs', 500, 200);
$chart->setScale(0, 100);
$data0 = new GoogleChartData($values[0]);
$chart->addData($data0);
$data1 = new GoogleChartData($values[1]);
$data1->setColor(array('FFC6A5', 'FFFF42', 'DEF3BD', '00A5C6', 'DEBDDE'));
$chart->addData($data1);
$marker = new GoogleChartLineMarker();
$marker->setData($data0);
$marker->setSize(5);
$marker->setPoints(5);
$chart->addMarker($marker);
$marker = new GoogleChartLineMarker();
$marker->setData($data0);
$marker->setColor('6699cc');
$marker->setSize(5);
$marker->setPoints(0, 5);
$marker->setZOrder(-0.5);
$chart->addMarker($marker);
$data2 = new GoogleChartData($values[2]);
$marker = new GoogleChartShapeMarker('a');
<?php

require '../lib/GoogleVennDiagram.php';
//~ $chart = new GoogleVennDiagram(300, 150);
//~ $data = new GoogleChartData(array(10,10));
//~ $data->setColor(array('FF0000', '00FF00'));
//~ $data->setLegends(array('A','B'));
//~ $chart->addData($data);
//~ $chart->setIntersectAB(1);
//~ var_dump($chart->getQuery());
//~ printf('<iframe src="%s" width="500" height="500"></iframe>',$chart->getValidationUrl());
//~ echo $chart->toHtml();
//~ unset($chart);
$chart = new GoogleVennDiagram(300, 150);
$data = new GoogleChartData(array(10, 20, 30));
$data->setColor(array('FF0000', '00FF00', '0000FF'));
$data->setLegends(array('A', 'B', 'C'));
$data->setLabels(array('A', 'B', 'C'));
$chart->addData($data);
$chart->setIntersectAB(1);
$chart->setIntersectAC(2);
$chart->setIntersectBC(3);
var_dump($chart->getQuery());
printf('<iframe src="%s" width="500" height="500"></iframe>', $chart->getValidationUrl());
echo $chart->toHtml();
//~ echo $chart;
$line->setLegend('Us');
$chart->addData($line);
$marker = new GoogleChartShapeMarker(GoogleChartShapeMarker::X);
$marker->setData($line);
$marker->setColor('6699cc');
$chart->addMarker($marker);
$marker = new GoogleChartTextMarker(GoogleChartTextMarker::VALUE);
$marker->setData($line);
$chart->addMarker($marker);
$line = new GoogleChartData($values[1]);
$line->setDash(2, 2);
$line->setColor('6699cc');
$chart->addData($line);
$line = new GoogleChartData($values[2]);
$line->setLegend('The others');
$line->setColor('ff0000');
$chart->addData($line);
$marker = new GoogleChartShapeMarker(GoogleChartShapeMarker::CIRCLE);
$marker->setData($line);
$marker->setColor('ff0000');
$chart->addMarker($marker);
$y_axis = new GoogleChartAxis('y');
$chart->addAxis($y_axis);
$x_axis = new GoogleChartAxis('x');
$x_axis->setTickMarks(5);
$x_axis->setDrawLine(false);
$x_axis->setTickColor('ff0000');
$chart->addAxis($x_axis);
if (isset($_GET['debug'])) {
    var_dump($chart->getQuery());
    echo $chart->validate();
<?php

/**
 * This chart could use the undocumented parameter "lfi".
 * See http://cse-mjmcl.cse.bris.ac.uk/blog/2007/12/23/1198436217875.html
 */
require '../lib/GoogleChart.php';
$values = array(34, 18, 21, 70, 53, 39, 39, 30, 13, 15, 4, 8, 5, 8, 4, 8, 44, 16, 16, 3, 10, 7, 5, 20, 20, 28, 44);
$chart = new GoogleChart('ls', 75, 30);
$data = new GoogleChartData($values);
$data->setThickness(1);
$data->setColor('0077CC');
$data->setFill('E6F2FA');
$chart->addData($data);
if (isset($_GET['debug'])) {
    var_dump($chart->getQuery());
    echo $chart->validate();
    echo $chart->toHtml();
} else {
    header('Content-Type: image/png');
    echo $chart;
}
<?php

require '../lib/GoogleScatterChart.php';
$chart = new GoogleScatterChart(300, 150);
$x_axis = new GoogleChartAxis('x');
$chart->addAxis($x_axis);
$y_axis = new GoogleChartAxis('y');
$chart->addAxis($y_axis);
//~ $chart->setScale(0,100);
//~ $chart->setDataFormat(GoogleChart::EXTENDED_ENCODING);
$data = array(array(12, 98, 84), array(75, 27, 69), array(23, 56, 47), array(68, 58, 60), array(34, 18, 64));
$data = new GoogleChartData($data);
$data->setColor('FF0000');
$data->setLegend('Cats');
$chart->addData($data);
//~ var_dump($chart->getQuery());
//~ printf('<iframe src="%s" width="500" height="500"></iframe>',$chart->getValidationUrl());
//~ echo $chart->toHtml();
$data = array(array(87, 60, 23), array(41, 34, 81), array(96, 79, 94), array(71, 74, 93), array(9, 76, 54));
$data = new GoogleChartData($data);
$data->setColor('0000FF');
$data->setLegend('Dogs');
$chart->addData($data);
//~ var_dump($chart->getQuery());
//~ printf('<iframe src="%s" width="500" height="500"></iframe>',$chart->getValidationUrl());
//~ echo $chart->toHtml();
echo $chart;
function sparklines()
{
    $values = array(34, 18, 21, 70, 53, 39, 39, 30, 13, 15, 24, 78, 85, 88, 74, 98, 44, 16, 16, 33, 50, 47, 55, 20, 20, 28, 44);
    $chart = new GoogleChart('ls', 75, 30);
    $chart->setFill('73A2BD');
    $data = new GoogleChartData($values);
    $data->setThickness(1);
    $data->setColor('C02942');
    $data->setFill('D95B43');
    $chart->addData($data);
    return $chart->getUrl();
}