$myData = new pData(); /* Add data in your dataset */ $myData->addPoints(array(1, 3, 4, 3, 5)); /* Create the cache object */ $myCache = new pCache(array("CacheFolder" => "../cache")); /* Compute the hash linked to the chart data */ $ChartHash = $myCache->getHash($myData); /* Test if we got this hash in our cache already */ if ($myCache->isInCache($ChartHash)) { /* If we have it, get the picture from the cache! */ $myCache->saveFromCache($ChartHash, "pictures/example.cache.png"); } else { /* Create a pChart object and associate your dataset */ $myPicture = new pImage(700, 230, $myData); /* Choose a nice font */ $myPicture->setFontProperties(array("FontName" => "../fonts/Forgotte.ttf", "FontSize" => 11)); /* Define the boundaries of the graph area */ $myPicture->setGraphArea(60, 40, 670, 190); /* Draw the scale, keep everything automatic */ $myPicture->drawScale(); /* Draw the scale, keep everything automatic */ $myPicture->drawSplineChart(); /* Do some cosmetics */ $myPicture->drawGradientArea(0, 0, 700, 20, DIRECTION_VERTICAL, array("StartR" => 0, "StartG" => 0, "StartB" => 0, "EndR" => 50, "EndG" => 50, "EndB" => 50, "Alpha" => 100)); $myPicture->setFontProperties(array("FontName" => "../fonts/Silkscreen.ttf", "FontSize" => 6)); $myPicture->drawText(10, 13, "Test of the pCache class", array("R" => 255, "G" => 255, "B" => 255)); /* Push the rendered picture to the cache */ $myCache->writeToCache($ChartHash, $myPicture); /* Render the picture */ $myPicture->render("pictures/example.cache.png"); }
function RenderValueChart(&$debug2) { $conditions = [["BETWEEN 1 AND 19"], ["BETWEEN 20 AND 49"], ["BETWEEN 50 AND 99"], ["BETWEEN 100 AND 199"], ["BETWEEN 200 AND 299"], ["BETWEEN 300 AND 499"], ["BETWEEN 500 AND 999"], ["> 999"]]; $label = ["1-19", "20-49", "50-99", "100-199", "200-299", "300-499", "500-999", ">1000"]; coinValueCount($conditions, $array_result); /* Create and populate the pData object */ $MyData = new pData(); $MyData->addPoints($array_result, "Värde (kr)"); $MyData->setAxisName(0, "Antal"); $MyData->addPoints($label, "Months"); $MyData->setSerieDescription("Months", "Month"); $MyData->setAbscissa("Months"); /* Create the cache object */ $myCache1 = new pCache(array("CacheFolder" => PCHART_PATH . "/class/cache")); /* Compute the hash linked to the chart data */ $ChartHash1 = $myCache1->getHash($MyData); /* Test if we got this hash in our cache already */ if ($myCache1->isInCache($ChartHash1)) { /* If we have it, get the picture from the cache! */ $myCache1->saveFromCache($ChartHash1, WWW_PATH . "/tmp/valuechart.png"); $debug2 = "Old image"; } else { /* Create the pChart object */ $myPicture = new pImage(700, 400, $MyData); /* Turn of Antialiasing */ $myPicture->Antialias = TRUE; /* Add a border to the picture */ $myPicture->drawRectangle(0, 0, 699, 399, array("R" => 0, "G" => 0, "B" => 0)); /* Set the default font */ $myPicture->setFontProperties(array("FontName" => PCHART_PATH . "/fonts/Forgotte.ttf", "FontSize" => 15, "R" => 80, "G" => 80, "B" => 80)); /* Define the chart area */ $myPicture->setGraphArea(60, 40, 650, 350); /* Draw the scale */ $scaleSettings = array("GridR" => 200, "GridG" => 200, "GridB" => 200, "DrawSubTicks" => TRUE, "CycleBackground" => TRUE, "Mode" => SCALE_MODE_START0); $myPicture->drawScale($scaleSettings); /* Write the chart legend */ $myPicture->drawLegend(340, 12, array("Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL)); /* Turn on shadow computing */ $myPicture->setShadow(TRUE, array("X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10)); /* Draw the chart */ $myPicture->setShadow(TRUE, array("X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10)); $settings = array("Gradient" => TRUE, "GradientMode" => GRADIENT_EFFECT_CAN, "DisplayPos" => LABEL_POS_INSIDE, "DisplayValues" => TRUE, "DisplayR" => 255, "DisplayG" => 255, "DisplayB" => 255, "DisplayShadow" => TRUE, "Surrounding" => 10); $myPicture->drawBarChart(); /* Push the rendered picture to the cache */ $myCache1->writeToCache($ChartHash1, $myPicture); /* Render the picture (choose the best way) */ $myPicture->Render(WWW_PATH . "/tmp/valuechart.png"); $debug2 = "Picture rendered"; } }
$data->setXAxisName("Zeit"); // Create the pChart object $picture = new pImage($width, $height, $data); // $picture->Antialias = false; // Draw the background $Settings = array("R" => 00, "G" => 250, "B" => 250, "Dash" => 1, "DashR" => 0, "DashG" => 0, "DashB" => 0); $picture->drawFilledRectangle(0, 0, $width, $height, $Settings); // Overlay with a gradient $Settings = array("StartR" => 0, "StartG" => 0, "StartB" => 0, "EndR" => 0, "EndG" => 0, "EndB" => 0, "Alpha" => 100); $picture->drawGradientArea(0, 0, $width, $height, DIRECTION_VERTICAL, $Settings); // Add a border to the picture $picture->drawRectangle(0, 0, $width - 1, $height - 1, array("R" => 0, "G" => 0, "B" => 0)); // title $picture->setFontProperties(array("FontName" => $fontText, "FontSize" => 14, "R" => 255, "G" => 255, "B" => 255)); // $picture->drawText(60,25,$title, array("FontSize"=>20)); $picture->drawText(70, 25, strftime("%d. %b %Y", $from) . " -> " . strftime(" %d. %b %Y %H:%M", $to), array("FontSize" => 18)); // scale $picture->setGraphArea(70, 30, $width, $height - 100); $picture->drawFilledRectangle(70, 30, $width, $height - 100, array("R" => 255, "G" => 255, "B" => 255, "Surrounding" => -200, "Alpha" => 5)); $picture->drawScale(array("LabelingMethod" => LABELING_DIFFERENT, "DrawSubTicks" => false, "MinDivHeight" => $Div, "LabelSkip" => $skipTicks, "DrawXLines" => $XLines, "LabelRotation" => 45, "RemoveSkippedAxis" => TRUE)); // $picture->setShadow(true, array("X"=>1, "Y"=>1, "R"=>0, "G"=>0, "B"=>0, "Alpha"=>10)); $picture->setFontProperties(array("FontName" => $fontScale, "FontSize" => 6, "R" => 0, "G" => 0, "B" => 0)); $picture->drawSplineChart(array("DisplayValues" => false, "DisplayColor" => DISPLAY_AUTO)); // $picture->drawLineChart(array("DisplayValues"=>false,"DisplayColor"=>DISPLAY_AUTO)); $picture->setShadow(false); $picture->drawLegend(75, $height - $height + 45, array("Style" => LEGEND_ROUND, "Family" => LEGEND_FAMILY_CIRCLE, "Mode" => LEGEND_HORIZONTAL, "FontSize" => 11)); $cache->writeToCache($chartHash, $picture); $picture->Stroke(); } $dd = time() - $start; syslog(LOG_DEBUG, "p4: --------- done in {$dd} seconds");