public function testChts()
 {
     $this->assertEquals($this->chart->hasChts(), false);
     $this->assertEquals($this->chart->computeChts(), '000000,12');
     // setTitleColor()
     $this->chart->setTitleColor('00ff00');
     $this->assertEquals($this->chart->computeChts(), '00ff00,12');
     // setTitleSize()
     $this->chart->setTitleSize('20');
     $this->assertEquals($this->chart->computeChts(), '00ff00,20');
     // chts is null if no title
     $q = $this->chart->getQuery();
     $this->assertEquals(isset($q['chts']), false);
     // title make chts appears
     $this->chart->setTitle('foobar');
     $q = $this->chart->getQuery();
     $this->assertEquals(isset($q['chts']), true);
     $this->assertEquals($q['chts'], '00ff00,20');
 }
示例#2
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();
 }
$n = 10;
for ($i = 0; $i <= $n; $i += 1) {
    $v = rand($i, $i * 10);
    $values[0][] = $v;
    $values[1][] = $v - $i;
    $values[2][] = rand(100 - ($i + 10), 100 - 10 * $i);
}
$chart = new GoogleChart('lc', 600, 300);
$chart->setGridLines(10, 10);
$chart->setLegendPosition('r');
//~ $chart->setMargin(50);
$chart->setLegendSize(150, 20);
$chart->setFill('ffffcc');
$chart->setGradientFill(45, array('cccccc', 'ffffff', 'cccccc'), GoogleChart::CHART_AREA);
$chart->setTitle('Us versus the others.');
$chart->setTitleColor('999999')->setTitleSize(20);
$line = new GoogleChartData($values[0]);
$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]);
require '../lib/GoogleChart.php';
$sin = array();
$cos = array();
for ($i = 0; $i <= 360; $i += 10) {
    $sin[] = round(sin($i * M_PI / 180), 2);
    $cos[] = round(cos($i * M_PI / 180), 2);
}
$chart = new GoogleChart('lc', 500, 200);
$chart->setGridLines(25, 50, 1, 1);
$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');
示例#5
0
function sin_cos()
{
    $sin = array();
    $cos = array();
    for ($i = 0; $i <= 360; $i += 10) {
        $sin[] = round(sin($i * M_PI / 180), 2);
        $cos[] = round(cos($i * M_PI / 180), 2);
    }
    $chart = new GoogleChart('lc', 500, 200);
    $chart->setGridLines(25, 50, 1, 1);
    $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);
    return $chart->getUrl();
}