Beispiel #1
0
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";
    }
}
Beispiel #2
0
/* CAT:Misc */
/* Include all the classes */
include "../class/pDraw.class.php";
include "../class/pImage.class.php";
include "../class/pData.class.php";
include "../class/pCache.class.php";
/* Create your dataset object */
$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));
Beispiel #3
0
    return;
}
// -------------------------
// charting
if (!chkDir($cache_dir)) {
    syslog(LOG_DEBUG, "Can't create directory " . $cache_dir);
}
$data = new pData();
$cache = new pCache(array("CacheFolder" => $cache_dir));
// fill data struct
$data->addPoints($times, "Timestamps");
foreach ($series as $sensor => $serie) {
    $data->addPoints($serie, $sensor);
}
$chartHash = $cache->getHash($data);
if ($cache->isInCache($chartHash)) {
    syslog(LOG_DEBUG, "p4: got from cache");
    $cache->strokeFromCache($chartHash);
} else {
    $points = $data->getSerieCount("Timestamps");
    //    if ($skipTicks == -1)
    //       $skipTicks = $points / ($width / 75);
    // $data->setAxisName(0, "Temperature");
    $data->setAxisUnit(0, $unit);
    $data->setAxisDisplay(0, AXIS_FORMAT_METRIC);
    // $data->setSerieDescription("Timestamp","Sampled Dates");
    $data->setAbscissa("Timestamps");
    // $data->setXAxisDisplay(AXIS_FORMAT_TIME, $xScaleFormat);
    $data->setXAxisName("Zeit");
    // Create the pChart object
    $picture = new pImage($width, $height, $data);