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(); }
/** * 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(); }
<?php require '../lib/GoogleChart.php'; require '../lib/markers/GoogleChartTextMarker.php'; require '../lib/markers/GoogleChartShapeMarker.php'; $values = array(); for ($i = 0; $i <= 10; $i += 1) { $values[] = rand(20, 80); } $chart = new GoogleChart('bvs', 500, 200); $chart->setScale(0, 100); $data = new GoogleChartData($values); $chart->addData($data); $marker = new GoogleChartTextMarker(GoogleChartTextMarker::FLAG, 'Hello, world!'); $marker->setData($data); $marker->setStep(2); $chart->addMarker($marker); // a fixed position marker $marker = new GoogleChartTextMarker(GoogleChartTextMarker::TEXT, 'Here'); $marker->setFixedPosition(0.25, 1); $chart->addMarker($marker); header('Content-Type: image/png'); echo $chart;
<?php require '../lib/GoogleChart.php'; require '../lib/markers/GoogleChartTextMarker.php'; $values = array(); for ($i = 0; $i <= 10; $i += 1) { $values[] = rand(20, 80); } $chart = new GoogleChart('bvs', 500, 200); $chart->setScale(0, 100); $data = new GoogleChartData($values); $chart->addData($data); $marker = new GoogleChartTextMarker(); $marker->setData($data); $chart->addMarker($marker); header('Content-Type: image/png'); echo $chart;
$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]); $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');
// don't forget to update the path here require '../../lib/GoogleChart.php'; require '../../lib/markers/GoogleChartShapeMarker.php'; require '../../lib/markers/GoogleChartTextMarker.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); // add a shape marker with a border $shape_marker = new GoogleChartShapeMarker(GoogleChartShapeMarker::CIRCLE); $shape_marker->setSize(6); $shape_marker->setBorder(2); $shape_marker->setData($data); $chart->addMarker($shape_marker); // add a value marker $value_marker = new GoogleChartTextMarker(GoogleChartTextMarker::VALUE); $value_marker->setData($data); $chart->addMarker($value_marker); header('Content-Type: image/png'); echo $chart;
function bar() { $values = array(10, 20, 30, 40, 50, 60, 70, 60, 50, 40, 30, 20, 10); $chart = new GoogleChart('bvs', 400, 200); $chart->setScale(0, 100); $chart->setGridLines(100, 20, 1, 1); $chart->setFill('9FC2D6', GoogleChart::CHART_AREA); $chart->setFill('73A2BD'); $data = new GoogleChartData($values); $chart->addData($data); $marker = new GoogleChartTextMarker(); $marker->setData($data); $marker->setColor('ffeaad'); $marker->setSize(14); $marker->setPlacement(GoogleChartTextMarker::CENTER, GoogleChartTextMarker::BAR_BASE, 0, 5); $chart->addMarker($marker); $y_axis = new GoogleChartAxis('y'); $chart->addAxis($y_axis); return $chart->getUrl(); }