/**
  * @return GoogleChartAxisCollection
  **/
 public function addAxis(GoogleChartAxis $axis)
 {
     $typeId = $axis->getType()->getId();
     if (isset($this->axes[$typeId])) {
         throw new WrongArgumentException('Axis already exists');
     }
     $this->axes[$typeId] = $axis;
     return $this;
 }
示例#2
0
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();
}
示例#3
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();
 }
示例#4
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();
}
示例#5
0
// 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>";
?>

示例#6
0
$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));
$y_axis->setFontSize(9);
$y_axis->setTickMarks(5);
$y_axis->setTickColor('ffffff');
$chart->addAxis($y_axis);
$x_axis = new GoogleChartAxis('x');
$x_axis->setDrawLine(false);
$x_axis->setLabels(array('27 apr', '04 may', '11 may', '18 may'));
$x_axis->setLabelPositions(0, 25.8, 51.8, 77.59999999999999);
$x_axis->setTickMarks(5);
$x_axis->setFontSize(9);
$chart->addAxis($x_axis);
if (isset($_GET['debug'])) {
    var_dump($chart->getQuery());
    echo $chart->validate();
    echo $chart->toHtml();
} else {
    header('Content-Type: image/png');
    echo $chart;
}
 /**
  * @dataProvider twoAxisDataProvider
  **/
 public function testTwoAxis($firstAxisData, $secondtAxisData, $result)
 {
     foreach ($result as $chartClass => $expectedString) {
         $views = GoogleChartDataSet::create()->setData($firstAxisData);
         $clicks = GoogleChartDataSet::create()->setData($secondtAxisData);
         $chart = new $chartClass();
         if ($chart->getData()->isNormalized()) {
             if ($views->getMax() >= 10) {
                 $base = pow(10, floor(log10($views->getMax())));
             } else {
                 $base = 0.1;
             }
             $views->setBase($base);
             if ($clicks->getMax() >= 10) {
                 $base = pow(10, floor(log10($clicks->getMax())));
             } else {
                 $base = 0.1;
             }
             $clicks->setBase($base);
         }
         $viewAxis = GoogleChartAxis::create(new GoogleChartAxisType(GoogleChartAxisType::Y))->setRange($views->getMinMax());
         $clickAxis = GoogleChartAxis::create(new GoogleChartAxisType(GoogleChartAxisType::R))->setRange($clicks->getMinMax());
         if ($chart->getData()->isNormalized()) {
             $viewAxis->setInterval($views->getBase());
             $clickAxis->setInterval($clicks->getBase());
         }
         $chart->setSize(GoogleChartSize::create()->setWidth(300)->setHeight(300))->addAxis($viewAxis)->addLine(GoogleChartLine::create()->setTitle('Показы')->setColor(Color::create('336699'))->setValue($views))->addAxis($clickAxis)->addLine(GoogleChartLine::create()->setTitle('Клики')->setColor(Color::create('339911'))->setValue($clicks));
         $this->assertEquals($expectedString, $chart->toString());
     }
 }
$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();
    echo $chart->toHtml();
} else {
    header('Content-Type: image/png');
    echo $chart;
}
$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();
    echo $chart->toHtml();
} else {
    header('Content-Type: image/png');
    echo $chart;
}
 public function testChxs()
 {
     $axis = new GoogleChartAxis('x');
     $this->assertEquals($axis->computeChxs(1), null);
     $axis->setLabelColor('ff0000');
     $this->assertEquals($axis->computeChxs(1), '1,ff0000');
     $axis->setFontSize(12);
     $this->assertEquals($axis->computeChxs(1), '1,ff0000,12');
     $axis->setLabelAlignment(-1);
     $this->assertEquals($axis->computeChxs(1), '1,ff0000,12,-1');
     $axis->setDrawLine(false);
     $this->assertEquals($axis->computeChxs(1), '1,ff0000,12,-1,t');
     $axis->setDrawTickMarks(false);
     $this->assertEquals($axis->computeChxs(1), '1,ff0000,12,-1,_');
     $axis->setTickColor('00ff00');
     $this->assertEquals($axis->computeChxs(1), '1,ff0000,12,-1,_,00ff00');
 }
示例#11
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();
}