JavaScript
function percentify(prob) {
var result = prob * 100;
result = result.toString().substring(0, 5) + "%";
return (result);
}
var unif = [0.1990, 0.2023, 0.1982, 0.1988, 0.2018];
var norm = [0.1213, 0.2359, 0.2865, 0.2346, 0.1217];
var doubexp = [0.0761, 0.2082, 0.4297, 0.2101, 0.0760];
var invnorm = [0.3031, 0.1643, 0.0630, 0.1650, 0.3046];
/* Change these two lines */
var LotteryA = invnorm;
var LotteryB = norm;
google.load('visualization', '1', {
packages: ['corechart', 'bar']
});
google.setOnLoadCallback(drawAnnotations);
function drawAnnotations() {
var dataA = new google.visualization.arrayToDataTable([
['Outcome', 'Frequency', {
role: 'annotation'
}],
['30 cents', LotteryA[0], percentify(LotteryA[0])],
['40 cents', LotteryA[1], percentify(LotteryA[1])],
['50 cents', LotteryA[2], percentify(LotteryA[2])],
['60 cents', LotteryA[3], percentify(LotteryA[3])],
['70 cents', LotteryA[4], percentify(LotteryA[4])]
]);
var optionsA = {
title: 'Lottery A',
width: 500,
height: 300,
legend: 'none',
bar: {
groupWidth: '95%'
},
vAxis: {
gridlines: {
count: 4
},
format: 'percent',
minValue: 0,
maxValue: 0.50
},
enableInteractivity: false
};
var dataB = new google.visualization.arrayToDataTable([
['Outcome', 'Frequency', {
role: 'annotation'
}],
['30 cents', LotteryB[0], percentify(LotteryB[0])],
['40 cents', LotteryB[1], percentify(LotteryB[1])],
['50 cents', LotteryB[2], percentify(LotteryB[2])],
['60 cents', LotteryB[3], percentify(LotteryB[3])],
['70 cents', LotteryB[4], percentify(LotteryB[4])]
]);
var optionsB = {
...