PHP Code:
## constants depending on the size/margins of image
$image_width = XXX; # width of image
$image_margin = XXX; # size of left/right margins if you do not want to edge
$value_max = XXXX; # max abs input value, probably 100
$value = From DB ;
# maximum width of color bar
$bar_max = floor( ($image_width - 2*$image_margin) / 2 ) ;
$image_midpoint = floor( $image_width/2 );
# actual width of color bar
$bar_length = (abs($value) /$value_max ) * $bar_max ;
# find left and right enpoints of bar, and the color
if( $value > 0 ){
$left = $image_midpoint ;
$right = $left + $bar_length ;
$color = POSITIVE_COLOR ;
} else {
$right = $image_midpoint ;
$left = $image_midpoint - $bar_length ;
$color = NEGATIVE_COLOR ;
}
Then use $left, $right, $color in your drawing program (GD based?).
Edit:
Like this