'
var pollForm = '';
$(document).ready(function(){
$("#pollQuestion").append(pollQuestion);
//buildBarChart();
deleteCookie('poll');
deleteCookie('hidePollModal');
let pollTaken = getCookie("poll");
let hidePollModal = getCookie("hidePollModal");
console.log('pollID: 169');
console.log('pollTaken:'+pollTaken);
console.log('hidePollModal:'+hidePollModal);
if (pollTaken == 169 || hidePollModal == 169) {
buildBarChart();
} else {
$("#pollQuestion").append(pollForm);
$("#pollResults").hide();
$("#pollResultsRespondents").hide();
$('#myModal').modal('show');
//setCookie('poll',169,1);
setCookie('hidePollModal',169,30);
}
});
function buildBarChart() {
var options = {
series: [],
chart: {
height: 250,
type: 'bar',
toolbar: {show: false},
fontFamily: 'Lato, sans-serif'
},
dataLabels: {enabled: false},
noData: {text: 'Loading...'},
colors: ['#7FCACF', '#B3B8B8', '#DD7E6F','#E4B87E', '#8582BE'],
plotOptions: {
bar: {
barHeight: '100%',
distributed: true,
horizontal: true,
dataLabels: {position: 'bottom'},
}
},
dataLabels: {
enabled: true,
textAnchor: 'start',
formatter: function (val, opt) {
let series = opt.w.config.series
let idx = opt.dataPointIndex
let count = series[0].data[idx].z;
return ' ' + val + '%';
},
offsetX: 0,
dropShadow: {enabled: false},
style: {
fontSize: '14px',
fontFamily: 'Lato, sans-serif' ,
fontWeight: 'normal',
colors: '#222222'
},
},
stroke: {
width: 2,
colors: ['#fff']
},
yaxis: {
labels:{show:true},
axisBorder:{show:true},
tooltip:{enabled:true},
labels: {
show: true,
minWidth: 0,
maxWidth: 160,
style: {
fontSize: '14px',
fontFamily: 'Lato, sans-serif' ,
fontWeight: 'normal',
colors: '#222222'
}
}
},
xaxis: {
labels:{show:true},
axisBorder:{show:true},
tooltip:{enabled:true}
},
legend: { show: false},
tooltip: {
enabled: false
},
grid: {
show:false,
padding: {
top: -10,
right: 0,
bottom: 0,
left: 0
}
},
tooltip: {
custom: function({ series, seriesIndex, dataPointIndex, w }) {
return (
'' +
"" +
w.globals.labels[dataPointIndex] +
"
" +
series[seriesIndex][dataPointIndex] +
"%" +
"
"
);
}
}
};
var chart = new ApexCharts(document.querySelector("#pollResults"), options);
chart.render();
$.getJSON('/poll/poll-results?pollID=169', function(response) {
chart.updateSeries([{
name: 'Responders',
data: response
}])
$('#respondents').html('Responses: '+response[0].respondents);
console.log('get poll results: '+ response[0].respondents);
});
};
function sendData(form){
$('form#pollForm').on('submit', function (e) {
e.preventDefault();
setCookie('poll',169,30);
var formData = {
pollID: 169,
answer: $(".form-check-input:checked").val()
};
var pollID = $("#pollID").val();
var answer = $(".form-check-input:checked").val();
$.ajax({
type: 'post',
url: '/tally-poll?pollID='+pollID+'&answer='+answer,
data: formData,
success: function () {
$("#pollForm").hide();
$("#pollResults").show();
$("#pollResultsRespondents").show();
console.log('/poll/poll-results?pollID='+pollID+'&answer='+answer);
buildBarChart();
},
error : function(result){
$("#pollForm").hide();
form.parent().replaceWith(pollAnswerBad); // should replace the form's parent div with the result
}
});
});
};