Exemplo n.º 1
0
    function PieChart($angle_deg = NULL)
    {
        $width = 400;
        $height = 260;
        $cx = $width / 2;
        $cy = $height / 2;
        $r = 100;
        $svg = '<div class="img-question text-center">
					<svg width="' . $width . '" height="' . $height . '">';
        // Show angle
        if ($angle_deg) {
            if ($angle_deg == 360) {
                $svg .= DrawCircle($cx, $cy, $r, $stroke = 'black', $strokewidth = 0, $fill = '#CCC');
            } else {
                $svg .= DrawPieChart($cx, $cy, $r, 0, $angle_deg, $fill = '#CCC');
            }
            list($x1, $y1) = polarToCartesian($cx, $cy, $r, 0);
            list($x2, $y2) = polarToCartesian($cx, $cy, $r, $angle_deg);
            $svg .= DrawLine($cx, $cy, $x1, $y1);
            $svg .= DrawLine($cx, $cy, $x2, $y2);
        }
        // Circle
        $svg .= DrawCircle($cx, $cy, $r);
        // Ticks for every 10°
        for ($i = 0; $i < 36; $i++) {
            $angle = $i * 10;
            list($x1, $y1) = polarToCartesian($cx, $cy, $r + 5, $angle);
            list($x2, $y2) = polarToCartesian($cx, $cy, $r - 5, $angle);
            $svg .= DrawLine($x1, $y1, $x2, $y2);
        }
        // Show hint degrees
        $svg .= DrawText($cx + $r + 10, $cy + 7, '0°', 15);
        $svg .= DrawText($cx + $r + 5, $cy - 13, '10°', 15);
        $svg .= DrawText($cx - 8, $cy - $r - 7, '90°', 15);
        $svg .= DrawText($cx - $r - 40, $cy + 7, '180°', 15);
        $svg .= DrawText($cx - 15, $cy + $r + 22, '270°', 15);
        $svg .= '</svg></div>';
        return $svg;
    }
Exemplo n.º 2
0
<?php

include "statistics_percentages.php";
include "statistics_series_total_sum.php";
include "pChart/class/pData.class.php";
include "pChart/class/pDraw.class.php";
include "pChart/class/pImage.class.php";
include "pChart/class/pPie.class.php";
include "statistics_description_text.php";
$width = 760;
$height = 500;
$pChart = new pData();
$pChartPicture = new pImage($width, $height, $pChart);
$Settings = array("R" => 255, "G" => 255, "B" => 255);
$pChartPicture->drawFilledRectangle(0, 0, $width, $height, $Settings);
DrawPieChart($pChart, $pChartPicture, $width / 2 - 50, $height / 2 + 30, $compare_column, $distinct_array_counts, $distinct_array);
$headerText = array("Align" => TEXT_ALIGN_BOTTOMMIDDLE, "FontName" => "pChart/fonts/arial.ttf", "FontSize" => 14, "R" => 80, "G" => 80, "B" => 80);
$pChartPicture->drawText($width / 2, 25, ucfirst($table) . " - Prosenttiosuudet", $headerText);
$description .= GetYearsDescription($years);
$description .= " - (" . GetSeriesTotalSum($pChart) . " kpl)";
if (strlen($description) > 120) {
    $description = substr($description, strpos($description, "joissa"));
}
$textSettings = array("Align" => TEXT_ALIGN_BOTTOMMIDDLE, "FontSize" => 11);
$pChartPicture->drawText($width / 2, 45, $description, $textSettings);
$pChartPicture->autoOutput("{$table}.png");
function DrawPieChart($pChart, $pChartPicture, $x, $y, $name, $values, $labels)
{
    $pChart->removeSerie("Serie");
    $pChart->removeSerie("Labels");
    $pChart->addPoints($values, "Serie");