I am using the following code for a "Google Chart". This is for the pie-chart.
#! /bin/bash
export DISPLAY=":11.0"
## Define variables
pname1=$(awk 'NR == 1 {print $1}' /home/gdata)
active1=$(awk 'NR == 1 {print $2}' /home/gdata)
total1=$(awk 'NR == 1 {print $3}' /home/gdata)
percent1=$(awk 'NR == 1 {print $4}' /home/gdata)
TEMP=$(mktemp -t chart.XXXXX)
cat > $TEMP <<EOF
<html>
<head>
<!--Load the AJAX API-->
<script type="text/javascript" src="https://www.google.com/jsapi"> </script>
<script type="text/javascript">
// Load the Visualization API and the piechart package.
google.load('visualization', '1.0', {'packages':['corechart']});
// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawChart);
// Callback that creates and populates a data table,
// instantiates the pie chart, passes in the data and
// draws it.
function drawChart() {
// Create the data table.
var data = new google.visualization.DataTable();
data.addColumn('string', 'Title');
data.addColumn('number', 'Value');
data.addRows([
['Active', $active1],
['Total', $total1]
]);
// Set chart options
var options = {'title':'$pname1 $percent1',
'width':400,
'height':300};
// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.PieChart(document.getElementById('chart_div1'));
chart.draw(data, options);
}
</script>
</head>
<body>
<!--Div that will hold the pie chart-->
<table class="columns">
<tr>
<td><div id="chart_div1" style="border: 1px solid #ccc"></div></td>
</tr>
</table>
</body>
</html>
EOF
# open browser
case $(uname) in
Darwin)
open -a /Applications/Google\ Chrome.app $TEMP
;;
Linux|SunOS)
firefox $TEMP
;;
esac
What is happening is my variables, $active and $total, do not match the $percent variable when the chart is rendered. For instance, in this chart the "total" represents 483 and the "active" represents 85. 85 is 17.6% of 483. On the pie chart, 85 shows as 15%.
Is there no way to make the chart try to make up the percentage as a total of 483, instead of 100?