Visualforce Page
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | <apex:page controller="CalendarChart"> <apex:form > <html> <head> <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> <script type="text/javascript"> google.charts.load('current', {'packages':['calendar']}); google.charts.setOnLoadCallback(drawChart); var countDate = '{!CDate}'; countDate = countDate.replace("[",""); countDate = countDate.replace("]",""); var countDateArr=countDate.split(','); var countValue = '{!CValue}'; countValue = countValue.replace("[",""); countValue = countValue.replace("]",""); var countValueArr=countValue.split(','); function drawChart() { var dataTable = new google.visualization.DataTable(); dataTable.addColumn({ type: 'date', id: 'Date' }); dataTable.addColumn({ type: 'number', id: 'Won/Loss' }); for (var i = 0; i < countValueArr.length; i++) { var j=i+1; var cd=countDateArr[i].replace('-',','); cd=cd.replace('-',','); dataTable.addRow([new Date(cd), Number(countValueArr[i])]); } var options = { title: "My Chart", height: 350, }; var chart = new google.visualization.Calendar(document.getElementById('chart_div')); chart.draw(dataTable, options); } </script> </head> <body> <div id="chart_div"></div> </body> </html> </apex:form> </apex:page> |
Apex
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | public class CalendarChart { public List<String> CDate{get;set;} public List<Integer> CValue{get;set;} public List<DailyCount__c> dcList{get;set;} public CalendarChart(){ CDate = new List<String>(); CValue = new List<Integer>(); Integer dd; Integer month; Integer year; dcList = [SELECT date__c,count__c FROM DailyCount__c]; for(DailyCount__c dc:dcList){ dd = dc.date__c.day(); month=dc.date__c.month(); year = dc.date__c.year(); CDate.add(year+'-'+month+'-'+dd); CValue.add(Integer.valueOf(dc.count__c)); } } } |
Watch Complete Video tutorial blow
If you have any question please leave a comment below.
If you would like to add something to this post please leave a comment below.
Share this blog with your friends if you find it helpful somehow !
Thanks
Keep Coding
0 Comments