Scripts
BI dashboard meter
Met deze dashboardmeter kun je percentages leuk weergeven. Ik heb deze dashboardmeter gemaakt aan de hand van de taartgrafiek die hier ook ergens op de site staat. Ik kon nergens iets dergelijks vinden, dus heb ik m.b.v. vandat script deze weten te maken. Ik heb er niet megaveel tijd voor, dus heb geen voorbeeld beschikbaar. Er kunnen ook wat kleine bugjes in zitten, maar dat komt omdat het script niet geheel dynamisch is. Alleen het percentage kan worden ingegeven middels een querystring ($_GET) Veel plezier ermee! Download: http://rapidshare.com/files/324855301/dashboard_meter.zip.html
bi-dashboard-meter
<?php
/*
speedo.php
--
of
--
speedo.php?perc=63.8
*/
//
//
// maximaal percentage
$maxValue=100;
// minimaal percentage
$minValue=0;
// Bereken tussenwaarde
$tussenwaarde = $maxValue-$minValue;
/*------------------------------------*/
//Controle percentage */
/*------------------------------------*/
if ((isset($_GET['perc']) && is_numeric($_GET['perc']))) {
if ($_GET['perc'] < $minValue || $_GET['perc'] > $maxValue) {
$img2 = imagecreate(600, 100);
$black2 = imagecolorallocate($img2, 0, 0, 0);
imagecolortransparent($img2, $black2);
imagettftext($img2, 7, 0, 0, 9, $black2, "trebuc.ttf", 'Error: Het opgegeven percentage is ongeldig!');
/*------------------------------------*/
// Errortekst outputten */
/*------------------------------------*/
header("Content-type: image/png");
imagepng($img2);
imagedestroy($img2);
}
}
$percentage = $_GET['perc'];
// kleuren definieren
$colors = Array();
$colors[] = '#FFFFFF';
$colors[] = '#FF0000';
$colors[] = '#FFAA00';
$colors[] = '#AAFF2A';
// kleurvlakken berekenen
$input = Array();
$input[] = array(number_format($maxValue*0.34,2,".",""),'');
$input[] = array(number_format((($maxValue*0.66)/(10/2.5)),2,".",""),'');
$input[] = array(number_format((($maxValue*0.66)/(10/3)),2,".",""),'');
$input[] = array(number_format((($maxValue*0.66)/(10/4.5)),2,".",""),'');
/*-------------------------------
Script gemaakt door D@rk_force
Email: [email protected]
Voorbeeld:
Sites Gepubliceerd:
http://www.phphulp.nl
http://www.tweakzone.nl
http://www.phpfreakz.nl
http://www.phpv.nl
http://flaming.lumix.nl
Script altered voor een speed-o-meter door; Wouter van der Burg
Sites Gepubliceerd:
http://www.phphulp.nl
-------------------------------*/
error_reporting(E_ALL);
//Diameter van de cirkel
$conf['diameter']=175;
//Breedte legende, moet breder worden als de resultaten er niet op kunnen
$conf['legende']=0;
//Hoe breed is de rand van de cirkel
$conf['breedte_rand']=0;
//Titel vand de grafiek
$conf['titel']='';
//Kleur van lijnen en tekst, zwart is het best te gebruiken. In hex vormaat
//Meer over hex kleuren vind je hier http://html-color-codes.com/
$conf['Text-line-color']='#000000';
//Sorteren invoer
/*------------------------------------*/
//Input berekenen
/*------------------------------------*/
//
for($a=0;$a<count($input);$a++){
if ($input[$a][0] > 0) {
//Hoeveel graden van de cirkel
$input[$a][2]=(($input[$a][0]/$maxValue)*360);
//Vorige aantal graden
if($a>0){
$previous=$input[$a-1][4];
}else{
$previous=29;
}
//Beginnen cirkel deel
$input[$a][3]=$previous;
//Eindigen cirkel deel
$input[$a][4]=$input[$a][2]+$previous;
//Procent van 100
$input[$a][5]=round((100/$maxValue)*$input[$a][0],2);
}
}
/*------------------------------------*/
//CIRKEL TEKENEN
/*------------------------------------*/
//Hoofd circkel
$hoofd['Xas']=(($conf['diameter']+40)/2); // plaats cirkel in breedte
$hoofd['Arcw']=$conf['diameter']; // wijdte van cirkel
$hoofd['Arch']=$conf['diameter']; // hoogte van cirkel
$hoofd['Arcs']=151; // begin rand cirkel
$hoofd['Arce']=389; // eind rand cirkel
//Kantelen
$hoofd['Arch']=sin(deg2rad((45*2))) * $hoofd['Arcw']; // kantelen van cirkel
$hoofd['Yas']=($hoofd['Arch']/2)+22; // plaats cirkel in hoogte
//Randje cirkel
$rand['kantel']=0;
$text['height']=3;
$text['tlh']=2;
$text['dotx']=20+$hoofd['Arcw'];
/*------------------------------------*/
//Figuur tekenen
/*------------------------------------*/
/*------------------------------------*/
//Kleuren maken
/*------------------------------------*/
$height = ($hoofd['Yas']*2)+$rand['kantel']+2;
$width = $conf['diameter']+$conf['legende']+40;
$img = imagecreate($width, $height);
$bg = imagecolorallocate($img, 255, 255, 255);
imagecolortransparent($img, $bg);
/*------------------------------------*/
//Textkleur omzetten
/*------------------------------------*/
preg_match('/(#)*([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})/',$conf['Text-line-color'],$hex);
$conf['r']=hexdec($hex[2]);
$conf['g']=hexdec($hex[3]);
$conf['b']=hexdec($hex[4]);
$black = imagecolorallocate($img, $conf['r'], $conf['g'], $conf['b']);
$textcolor = $black;
for($a=0;$a<count($input);$a++){
preg_match('/(#)*([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})/',$colors[$a],$hex);
$colors[$a] = imagecolorallocate($img, hexdec($hex[2]), hexdec($hex[3]), hexdec($hex[4]));
$color1=(hexdec($hex[2])>=100)?(hexdec($hex[2])-100):0;
$color2=(hexdec($hex[3])>=100)?(hexdec($hex[3])-100):0;
$color3=(hexdec($hex[4])>=100)?(hexdec($hex[4])-100):0;
$colors_d[$a] = imagecolorallocate($img, $color1, $color2, $color3);
}
/*------------------------------------*/
//Hoofd delen van cirkel
/*------------------------------------*/
// Kleurvlakken genereren
for($a=0;$a<count($input);$a++){
imagefilledarc($img, $hoofd['Xas'], $hoofd['Yas'], $hoofd['Arcw'], $hoofd['Arch'], $input[$a][3], $input[$a][4], $colors[$a], IMG_ARC_PIE);
}
// Percentages rond de meter weergeven
imagettftext($img, 8, 0, $hoofd['Xas']+($conf['diameter']/2.1), $hoofd['Yas']+45, $textcolor, "trebuc.ttf", $maxValue."%");
imagettftext($img, 8, 0, $hoofd['Xas']+($conf['diameter']/2.30), $hoofd['Yas']-45, $textcolor, "trebuc.ttf", $tussenwaarde*0.75+($minValue)."%");
imagettftext($img, 8, 0, $hoofd['Xas']-7, $hoofd['Yas']-89, $textcolor, "trebuc.ttf", $tussenwaarde*0.5+($minValue)."%");
imagettftext($img, 8, 0, $hoofd['Xas']-93, $hoofd['Yas']-45, $textcolor, "trebuc.ttf", $tussenwaarde*0.25+($minValue)."%");
imagettftext($img, 8, 0, $hoofd['Xas']-($conf['diameter']/1.85), $hoofd['Yas']+45, $textcolor, "trebuc.ttf", $minValue."%");
// Berekenen positie van aanwijsstokje
$percentline=151; // max end is 389
$verschilmaxmin = 389-151;
if ((isset($percentage) && is_numeric($percentage))) {
if ($percentage >= $minValue && $percentage <= $maxValue) {
$linepos = ($verschilmaxmin/$maxValue)*($percentage-$minValue);
$percentline = $linepos+151;
}
}
$percentlineend=$percentline+1;
// tekenen aanwijsstokje
imagefilledarc($img, $hoofd['Xas'], $hoofd['Yas'], $hoofd['Arcw'], $hoofd['Arch'], $percentline, $percentlineend, $black, IMG_ARC_CHORD);
/*------------------------------------*/
//Zwart randje rond de cirkel */
/*------------------------------------*/
imagearc($img, $hoofd['Xas'], $hoofd['Yas'], $hoofd['Arcw'], $hoofd['Arch'], $hoofd['Arcs'], $hoofd['Arce'], $black);
/*------------------------------------*/
//Actueel percentage onderin zetten */
/*------------------------------------*/
imagettftext($img, 14, 0, $hoofd['Xas']-20, $hoofd['Yas']+55, $textcolor, "trebuc.ttf", number_format($percentage,1,".","").'%');
/*------------------------------------*/
// Goede Figuur outputten */
/*------------------------------------*/
header("Content-type: image/png");
imagepng($img);
imagedestroy($img);
?>
Reacties
0