#!/bin/bash url="http://chart.apis.google.com/chart?" # title chtt="What+are+the+top+3+issues+facing+Gentoo?" # color chco="45347b" # Use text encoding for data (floating-point numbers) chd="t:" chxt=x,y,x # y-axis range # max is also used later in the awk, divided by 100 YMAX="26" chxr="0,0,${YMAX}" while read i; do l=${i%:*} n=${i#*: } # Comment out if you want a total number for getting percentages # Total=163.0 (1.63) [[ $l = Total ]] && continue l="${l}" chxl=( "${chxl[@]}" "${l}" ) chd="${chd}${n}," done \ < <(awk '/^1/, /^2/ {print}' gentoo_survey.txt \ | grep ': [0-9]' gentoo_survey.txt \ | sort -t: -k2 -n -r \ | awk -F: \ 'BEGIN {other=0; tot=0} \ { tot+=$2; if ($2 > 3) printf("%s: %.1f\n", $1, $2/1.63/0.26); else other++} \ END {printf("%s: %.1f\n", "Other", other/1.63/0.26); print "Total: " tot}') # Reverse the order of labels for ((i=${#chxl[@]}, j=0; i>=0; i--, j++)); do newchxl[j]=${chxl[i]} done unset chxl for i in "${newchxl[@]}"; do chxl="${chxl}${i}|" done chxl="1:${chxl}2:|Percentage" # Label position chxp="2,50" # Strip off the last ones chd=${chd%,} chxl=${chxl%|} #chs="800x375" chs="600x500" # bar chart cht="bhg" echo "${url}chs=${chs}&cht=${cht}&chxr=${chxr}&chxp=${chxp}&chxt=${chxt}&chd=${chd}&chxl=${chxl}&chtt=${chtt}&chco=${chco}"