I am having an issue with displaying a report based on the election date. The function showReport() works fine when called on form load, but fails to work when called on button click.
Here are the report members:
<script>
function showReport(){
var from = $('#from').val();
var to = $('#to').val();
var str = $('#str').val();
if(from == '' && to == '')
{
var from = '$from';
var to = '$to';
}
$.ajax({
url: "crm_data_report.php?type="+str+"&from="+from+"&to="+to,
method: "POST",
success: function(data) {
console.log(data);
var date = [];
var value = [];
for(var i in data)
{
date.push(data[i].date);
value.push(data[i].value);
}
var color = Chart.helpers.color;
var chartdata = {
labels: date,
datasets :
[
{
label: 'Members',
backgroundColor: color(window.chartColors.red).alpha(0.5).rgbString(),
borderColor: window.chartColors.red,
borderWidth: 1,
data: value
}
]
};
var ctx = $("#mycanvas");
var barGraph = new Chart(ctx, {
type: 'bar',
data: chartdata
});
},
error: function(data) {
console.log(data);
}
});
}
The code I used to call the function on load and on button click is shown below:
<script>
$(document).ready(function(){
showReport();
});
$('#filter').click(function(){
showReport();
});
</script>