function pch_slicebar_graph($graph_type, $data, $period, $width, $height, $colors, $font, $round_corner, $font_size, $antialiasing = true) { /* CAT:Slicebar charts */ set_time_limit(0); // Dataset definition $myPicture = new pImage($width, $height); /* Turn of Antialiasing */ $myPicture->Antialias = $antialiasing; $myPicture->setFontProperties(array("FontName" => $font, "FontSize" => $font_size, "R" => 80, "G" => 80, "B" => 80)); // Round corners defined in global setup if ($round_corner != 0) { $radius = $height > 18 ? 8 : 0; } else { $radius = 0; } $thinest_slice = $width / $period; /* Color stuff */ $colorsrgb = array(); foreach ($colors as $key => $col) { $rgb = html2rgb($col); $colorsrgb[$key]['R'] = $rgb[0]; $colorsrgb[$key]['G'] = $rgb[1]; $colorsrgb[$key]['B'] = $rgb[2]; } $i = 0; foreach ($data as $d) { $color = $d['data']; $color = $colorsrgb[$color]; $ratio = $thinest_slice * $d['utimestamp']; $myPicture->drawRoundedFilledRectangle($i, 0, $ratio + $i, $height, $radius, array('R' => $color['R'], 'G' => $color['G'], 'B' => $color['B'])); $i += $ratio; } if ($round_corner) { /* Under this value, the rounded rectangle is painted great */ if ($thinest_slice <= 16) { /* Clean a bit of pixels */ for ($i = 0; $i < 7; $i++) { $myPicture->drawLine(0, $i, 6 - $i, $i, array('R' => 255, 'G' => 255, 'B' => 255)); } $end = $height - 1; for ($i = 0; $i < 7; $i++) { $myPicture->drawLine(0, $end - $i, 5 - $i, $end - $i, array('R' => 255, 'G' => 255, 'B' => 255)); } } } $myPicture->drawRoundedRectangle(0, 0, $width, $height - 1, $radius, array('R' => 157, 'G' => 157, 'B' => 157)); $myPicture->Stroke(); }
//$myPicture->drawFilledRectangle(3,0,$width-1,$height-4,array("R"=>120, "G"=>185, "B"=>255, "Dash"=>0, "DashR"=>255, "DashG"=>255, "DashB"=>255)); $myPicture->drawFilledRectangle(3, 0, $width - 1, $height - 4, array("R" => 120, "G" => 215, "B" => 180, "Dash" => 0, "DashR" => 255, "DashG" => 255, "DashB" => 255)); $myPicture->drawRectangle(3, 0, $width - 1, $height - 4, array("R" => 0, "G" => 0, "B" => 0)); $myPicture->drawFilledRectangle(0, 3, $width - 4, $height - 1, array("R" => 255, "G" => 255, "B" => 255, "Alpha" => 85)); $myPicture->drawRectangle(0, 3, $width - 4, $height - 1, array("R" => 0, "G" => 0, "B" => 0)); /* Overlay with a gradient */ // $Settings = array("StartR"=>219, "StartG"=>231, "StartB"=>139, "EndR"=>1, "EndG"=>138, "EndB"=>68, "Alpha"=>50); // $myPicture->drawGradientArea(0,0,800,350,DIRECTION_VERTICAL,$Settings); // $myPicture->drawGradientArea(0,0,700,20,DIRECTION_VERTICAL,array("StartR"=>0,"StartG"=>0,"StartB"=>0,"EndR"=>50,"EndG"=>50,"EndB"=>50,"Alpha"=>80)); /* Set the default font */ $myPicture->setFontProperties(array("FontName" => "./fonts/simhei.ttf", "FontSize" => $font_t, "R" => 0, "G" => 0, "B" => 0)); $myPicture->drawText(5, 5 + $font_t * 2, $chart_title); $myPicture->setFontProperties(array("FontName" => "./fonts/simhei.ttf", "FontSize" => $font, "R" => 0, "G" => 0, "B" => 0)); $myPicture->setGraphArea(55, 15 + $font_t * 2, $width * 0.9 - 50, $height - 50); /* Draw the scale */ $scaleSettings = array("FLOATING" => TRUE, "GridR" => 0, "GridG" => 0, "GridB" => 0, "GridAlpha" => 10, "DrawSubTicks" => TRUE, "Mode" => SCALE_MODE_START0, "CycleBackground" => FALSE, "LabelRotation" => 30, "LabelSkip" => round($row_number / ($width / 30))); $myPicture->drawScale($scaleSettings); /* Enable shadow computing */ $myPicture->setShadow(TRUE, array("X" => 1.5, "Y" => 1.5, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10)); /* Draw the line chart */ $myPicture->drawLineChart(); //$myPicture->drawPlotChart(array("DisplayValues"=>TRUE,"PlotBorder"=>TRUE,"BorderSize"=>2,"Surrounding"=>-60,"BorderAlpha"=>80)); /* Write the data bounds */ //$myPicture->writeBounds(); /* Write the chart legend */ $myPicture->setFontProperties(array("FontName" => "./fonts/simsun.ttc", "FontSize" => $font, "R" => 0, "G" => 0, "B" => 0)); $myPicture->drawLegend($width * 0.9 - 40, 30 + $font_t * 2, array("Style" => LEGEND_BOX, "Mode" => LEGEND_VERTICAL, "Alpha" => 10, "Margin" => 4, "R" => 255, "G" => 255, "B" => 255)); /* Render the picture (choose the best way) */ // $myPicture->Render("pictures/$chart_png.png"); $myPicture->Stroke();
function draw_3dpie_chart($WIDTH, $HEIGHT, $DATA, $CONFIG, $LEGEND, $FONT, $PALETTE = 'default') { /* Include all the pChart 2.0 classes */ include '../lib/pchart2/class/pDraw.class'; include '../lib/pchart2/class/pImage.class'; include '../lib/pchart2/class/pData.class'; include '../lib/pchart2/class/pPie.class'; $COLORS = ArtefactTypeSurvey::get_palette_colors($PALETTE); /* Create your dataset object */ $myData = new pData(); /* Add data in your dataset */ if ($CONFIG['type'] == 'percent') { foreach ($DATA[0] as $value) { if ($value['percent'] != 0) { $POINTS[] = $value['percent']; if ($LEGEND == 'key') { $LABELS[] = $value['key']; } if ($LEGEND == 'label') { $LABELS[] = $value['label']; } } } $myData->addPoints($POINTS, $CONFIG['title']); $myData->setAxisUnit(0, '%'); } else { foreach ($DATA[0] as $value) { if ($value['value'] != 0) { $POINTS[] = $value['value']; if ($LEGEND == 'key') { $LABELS[] = $value['key']; } if ($LEGEND == 'label') { $LABELS[] = $value['label']; } } } $myData->addPoints($POINTS, $CONFIG['title']); $myData->setAxisUnit(0, ''); } /* Labels definition */ /* $myData->addPoints($LABELS,'Legend'); $myData->setSerieDescription('Legend',''); $myData->setAbscissa('Legend'); */ /* Will replace the whole color scheme by the selected palette */ $myData->loadPalette('lib/pchart2/palettes/' . $PALETTE . '.color', TRUE); /* Create a pChart object and associate your dataset */ $myPicture = new pImage($WIDTH, $HEIGHT, $myData); /* Draw border around the chart */ $myPicture->drawRectangle(0, 0, $WIDTH - 1, $HEIGHT - 1, array("R" => 0, "G" => 0, "B" => 0)); /* Draw chart background */ //$myPicture->drawFilledRectangle(0,0,$WIDTH,$HEIGHT,array("R"=>$COLORS[1]['R'],"G"=>$COLORS[1]['G'],"B"=>$COLORS[1]['B'],"Alpha"=>10)); /* Define the boundaries of the graph area */ //$myPicture->setGraphArea(20,20,$WIDTH-20,$HEIGHT-40); /* Choose a nice font */ switch ($FONT['type']) { case 'serif': $fontname = 'lib/pchart2/fonts/LiberationSerif-Regular.ttf'; break; case 'sans': $fontname = 'lib/pchart2/fonts/LiberationSans-Regular.ttf'; break; } $myPicture->setFontProperties(array('FontName' => $fontname, 'FontSize' => $FONT['size'])); /* Create label with survey name */ //$myPicture->drawText(20,$HEIGHT-30,$CONFIG['title'],array("DrawBox"=>true,"BoxRounded"=>true,"BoxR"=>$COLORS[1]['R'],"BoxG"=>$COLORS[1]['G'],"BoxB"=>$COLORS[1]['B'],"BoxAlpha"=>20,"Align"=>TEXT_ALIGN_MIDDLELEFT)); /* Create the pPie object */ $PieChart = new pPie($myPicture, $myData); /* Draw a simple pie chart */ $PIE_WIDTH = $WIDTH - 40; // 20px margin on left and right $PIE_HEIGHT = $HEIGHT - 60; // 20px margin on top and 40px on bottom (space for legend) if ($PIE_WIDTH >= $PIE_HEIGHT) { // Landscape orientation of the graph... $PieRadius = round($PIE_HEIGHT / 2); } else { // Portrait orientation of the graph... $PieRadius = round($PIE_WIDTH / 2); } $PieX = round($WIDTH / 2); $PieY = round($HEIGHT / 2); $PieChart->draw3DPie($PieX, $PieY, array("Radius" => $PieRadius, "SecondPass" => false, "DrawLabels" => false)); /* Build the PNG file and send it to the web browser */ $myPicture->Stroke(); }