<apex:page controller="WasteSplit" sidebar="false">
<!-- Google API inclusion -->
<apex:sectionHeader title="Google Charts" subtitle="Chart 2"/>
<apex:form >
<table align="center">
<td><b>Date From:</b>
<input id="t" name="datee" onfocus="DatePicker.pickDate(false,'t', false);"
size="12" tabindex="28" type="date" />
</td><td></td>
<td></td>
<td></td>
<td></td>
<td><b>Date To:</b>
<apex:outputText value="{0,date,dd/MM/yyyy}">
<apex:param value="{!NOW()}" />
</apex:outputText></td>
<td><input type="button" onclick="initCharts()" value="Go"></input></td>
<td><input id="exportCSV" type="button" onclick="window.open('/apex/CSVWasteSplit?name=' + Name + '&type=' + Type);" value="Export to CSV" style="display: none;"></input></td>
</table>
</apex:form>
<div id="chartBlock" style="width: 600px; height: 500px;"/>
<script type="text/javascript">
// Load the Visualization API and the piechart package.
google.load('visualization', '1', {'packages':['corechart']});
// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(initCharts);
function initCharts() {
var dateFrom= $('#t').val();
document.getElementById('chartBlock').innerHTML = '';
document.getElementById('exportCSV').style.display = 'none';
Name = '';
Type = '';
if(dateFrom != null && dateFrom != '')
{
WasteSplit.WasteSource(
dateFrom,function(result, event){
// load Column chart
if (event.status && event.result)
{
var visualization = new google.visualization.PieChart(document.getElementById('chartBlock'));
// Prepare table model for chart with columns
var data = new google.visualization.DataTable();
data.addColumn('string', 'Waste Name');
data.addColumn('number', 'Waste Type');
// add rows from the remoting results
for(var i=0; i<result.length;i++){
var finalBean= result[i];
data.addRow([finalBean.WasteName,finalBean.wastetype]);
}
//here m passing the the value of array list for exporting it to csv
if(finalBean.WasteName != null && finalBean.wastetype != null)
{
Name = finalBean.WasteName;
Type = finalBean.wastetype;
document.getElementById('exportCSV').style.display = 'block';
}
} else {
alert(event.message);
}
visualization.draw(data,{title:'Waste Service Split at Source',legend : {position: 'bottom', textStyle: {color: 'blue', fontSize: 10}}, width:window.innerWidth,vAxis:{textStyle:{color:'red', fontSize: 15}},hAxis:{title: 'Record Count',textStyle:{fontSize: 10},showTextEvery:1,slantedText:true}} );
}, {escape:true});
}
}
</script>
</apex:page>