speedometer chart
If you want a simple speedometer chart, and google's chart is just not what you want, here's a simple custom solution written in PHP. This should allow you to make any customizations you want.
It's easy to embed anywhere. All you have to do is include the script, and it will output the image to the browser. Then, you simply wrap it in a
html tag, like so:
Here's how to embed it directly.
If you are looking to customize it, look at this php script (image attachments at the bottom).
It's easy to embed anywhere. All you have to do is include the script, and it will output the image to the browser. Then, you simply wrap it in a
<img src="speedometer.php?v=30" />
Demo:Here's how to embed it directly.
If you are looking to customize it, look at this php script (image attachments at the bottom).
<?php
/**
* author websites-development.com
*/
/** background images settings - all transparent png
* the dial - has blank space, to allow for ledend text
* the arrow - has to be bigger, and positioned properly. The whole thing rotates
*/
define('DIAL', __DIR__."/speedometer.png"); // the dial backgound
define('BLANK_IMG', __DIR__."/blank.png"); // a blank PNG Image
define('NEEDLE', __DIR__."/arrow.png"); // the speedial arrow
define('POINT', __DIR__."/center.png"); // a pin-point image
// legend settings
define(FONT, __DIR__.'/arialbd.ttf'); // font for text
define(FONT_COLOR, '333366');
define(TXT_PADDING, 130);
$v = intval($_GET['v']);
$title = isset($_GET['title']) ? $_GET['title'] : 'Items';
$start = isset($_GET['start']) ? intVal($_GET['start']) : 0;
$end = isset($_GET['end']) ? intVal($_GET['end'] ) : 100;
SpeedometerChart($v, $title, $start, $end);
function SpeedometerChart( $value, $labeltitle='Items', $range_bottom=0, $range_top=100, $header=true ) {
// Basic check of input
if ($range_bottom > $range_top) {
$tmp = $range_bottom;
$range_top = $range_bottom;
$range_bottom = $tmp;
unset($tmp);
}
// prevent looping
if ($value > $range_top) $value = $range_top;
if ($value < $range_bottom) $value = $range_bottom;
// Determine angle to rotate the needle based on the range and value
$angle = (($value - $range_bottom) * 236)/($range_top - $range_bottom);
// load dial image
$dial = imagecreatefrompng(DIAL);
imageAlphaBlending($dial, true);
imageSaveAlpha($dial, true);
// write the legend text
$title = imagettftext( $dial, 13, 0, TXT_PADDING, 60, FONT_COLOR, FONT, $labeltitle );
//get the size of the number text, so we can align it
$number = imagettftext( $dial, 16, 0, TXT_PADDING, 5000, FONT_COLOR, FONT, number_format($value) );
// write the number text - align it center relative to legend title
imagettftext( $dial,16,0, TXT_PADDING+($title[2]-$title[0])/2 - ($number[2]-$title[0])/2 ,40, FONT_COLOR, FONT, number_format($value) );
// Pull in the Needle Image, enabling
$needleIMG = imagecreatefrompng(NEEDLE);
imageAlphaBlending($needleIMG, true);
imageSaveAlpha($needleIMG, true);
// get original Width and Height
$needle_x = imagesx($needleIMG);
$needle_y = imagesy($needleIMG);
// rotate the needle to it's position
$needleIMG = imagerotate($needleIMG,(-$angle+28),-1); // the original needle is horizontal, this makes sure it starts at negative (begining of dial)
// Get new width and height
$new_x = imagesx($needleIMG);
$new_y = imagesy($needleIMG);
// Create blank Image from png
$new_img = imagecreatefrompng(BLANK_IMG);
imageAlphaBlending($new_img, true);
imageSaveAlpha($new_img, true);
// Crop the image, leaving only the center part
imagecopy($new_img, $needleIMG, 0, 0, round(($new_x - $needle_x)/2), round(($new_y - $needle_y)/2), $needle_x, $needle_y);
// Position it over the proper 'Pin Point' for the needle
imagecopy($dial, $new_img, 0, 0, 0, 0, imagesx($dial), imagesy($dial));
// attach the pin-point image
$pointImg = imagecreatefrompng(POINT);
imagecopy($dial, $pointImg, 52, 53, 0, 0, imagesx($pointImg), imagesy($pointImg) );
if ( $header ) {
header("Content-Type: image/png");
}
imagepng($dial);
}
- admin's blog
- Login or register to post comments


How to downlad images
Hi, How can i get the images used in the speedometer example? thanks
Any one can give the complete
Any one can give the complete package used for speedometer including images ?
use it as a SaaS
have a look here: http://websites-development.com/tools/speedometer-chart
But if you want to customize and use your own, simply download all attachments and start playing with the script and images :)
See the list of attachments
See the list of attachments at the end of the post.
But be aware that if you want to change the graphics, for any reason, you should be aware the script manipulates them. So, it can tricky to fit them in the right spot, especially the arrow.