<?php
$active = 'results';
// this shows in the navbar which page is active
include 'FiverrHeader.php';
?>
<?php
// function to calculate the amount of votes
function amountVotes($question, $option) {
$conn =
mysqli_connect('localhost','basvaky59_lcomuth','itgUkCRi','basvaky59_lcomuth');
$query = "SELECT COUNT(*) as 'amount'
FROM prive
WHERE $question = '$option'";
$result = mysqli_query($conn, $query);
$row = mysqli_fetch_assoc($result);
return $row['amount'];
}
// calculate the total of the votes
// question 1
$AmountVotesQuestion1Option1 = amountVotes('question1', 'option1');
$AmountVotesQuestion1Option2 = amountVotes('question1', 'option2');
$AmountVotesQuestion1Option3 = amountVotes('question1', 'option3');
$AmountVotesQuestion1Option4 = amountVotes('question1', 'option4');
// question 2
$AmountVotesQuestion2Option1 = amountVotes('question2', 'option1');
$AmountVotesQuestion2Option2 = amountVotes('question2', 'option2');
$AmountVotesQuestion2Option3 = amountVotes('question2', 'option3');
$AmountVotesQuestion2Option4 = amountVotes('question2', 'option4');
// question 3
$AmountVotesQuestion3Option1 = amountVotes('question3', 'option1');
$AmountVotesQuestion3Option2 = amountVotes('question3', 'option2');
$AmountVotesQuestion3Option3 = amountVotes('question3', 'option3');
$AmountVotesQuestion3Option4 = amountVotes('question3', 'option4');
?>
<!--Loading the AJAX API -->
<script type='text/javascript'
src='https://www.gstatic.com/charts/loader.js'></script>
<script type='text/javascript'>
// Load the Visualization API and the piechart package.
google.charts.load('current', {'packages':['corechart']});
// Set a callback to run when the Google Visualization API is loaded.
google.charts.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.arrayToDataTable([
['Option 1, Option 2, Option 3, Option 4'],
<?php
echo "['Question 1', $AmountVotesQuestion1Option1,
$AmountVotesQuestion1Option2, $AmountVotesQuestion1Option3,
$AmountVotesQuestion1Option4],\n";
echo "['Question 2', $AmountVotesQuestion2Option1,
$AmountVotesQuestion2Option2, $AmountVotesQuestion2Option3,
$AmountVotesQuestion2Option4],\n";
echo "['Question 3', $AmountVotesQuestion3Option1,
$AmountVotesQuestion3Option2, $AmountVotesQuestion3Option3,
$AmountVotesQuestion3Option4],\n";
?>
]);
// Set chart options
var options = {
'width': 1500,
'height': 1200,
colors: ['#0000ff', '#ffff00', '#008000','#ff0000',
'#0000ff', '#ffff00','#00800', '#ff0000', '#0000ff','#ffff00', '#00800',
'#ff0000']
legend: { position: 'top', maxLines: 3 },
bar: { groupWidth: '75%' },
isStacked: true
};
// Instantiate and draw our chart, passing in some options.
var chart = new
google.visualization.BarChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
<div id='chart_div'></div>
<?php
echo '
<table id="table" cellpadding="10" cellspacing="0" border="1">
<tr>
<th>Amount of votes on question 1; option 1</th>
<th>Amount of votes on question 1; option 2</th>
<th>Amount of votes on question 1; option 3</th>
<th>Amount of votes on question 1; option 4</th>
<th>Amount of votes on question 2; option 1</th>
<th>Amount of votes on question 2; option 2</th>
<th>Amount of votes on question 2; option 3</th>
<th>Amount of votes on question 2; option 4</th>
<th>Amount of votes on question 3; option 1</th>
<th>Amount of votes on question 3; option 2</th>
<th>Amount of votes on question 3; option 3</th>
<th>Amount of votes on question 3; option 4</th>
</tr>
<tr>
<td>'. $AmountVotesQuestion1Option1 .' </td>
<td>'. $AmountVotesQuestion1Option2 .' </td>
<td>'. $AmountVotesQuestion1Option3 .' </td>
<td>'. $AmountVotesQuestion1Option4 .' </td>
<td>'. $AmountVotesQuestion2Option1 .' </td>
<td>'. $AmountVotesQuestion2Option2 .' </td>
<td>'. $AmountVotesQuestion2Option3 .' </td>
<td>'. $AmountVotesQuestion2Option4 .' </td>
<td>'. $AmountVotesQuestion3Option1 .' </td>
<td>'. $AmountVotesQuestion3Option2 .' </td>
<td>'. $AmountVotesQuestion3Option3 .' </td>
<td>'. $AmountVotesQuestion3Option4 .' </td>
</tr>
</table>
';
This is the code I used to make a barchart that displays the outcome of a
few polls. For some reason the chart doesn't show. I've tried several
things such as just putting numbers in the chart which worked in a
different php file but didn't in this file. I have no idea what to do now
and I would greatly appreciate it if someone is able to help me.
--
You received this message because you are subscribed to the Google Groups
"Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-visualization-api/f4cb6469-9cde-4a82-a107-19398d648d1bn%40googlegroups.com.