Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- global with sharing class AccountRemoter {
- @RemoteAction
- global static List<AggregateResult> getAccountList(){
- List<Account> accList=[select id,Name from account];
- List<AggregateResult> contactList = [ SELECT AccountId Id, COUNT(Id)
- numContacts FROM Contact WHERE AccountId IN (Select Id from Account) GROUP
- BY AccountId ORDER BY COUNT(Id) DESC LIMIT 10];
- return contactList;
- }
- }
- <apex:page Controller="AccountRemoter">
- <apex:includeScript value="{!$Resource.jquery}"/>
- <apex:includeScript value="{!$Resource.chartLibrary}"/>
- <canvas id="myChart" width="400" height="400"></canvas>
- <script>
- var names=[];
- Visualforce.remoting.Manager.invokeAction(
- '{!$RemoteAction.AccountRemoter.getAccountList}',
- function(result, event) {
- var test = result;
- var data=[];
- for (var i = 0; i< result.length ; i++){
- data.push(test[i]);
- }
- console.log(data[0]);
- console.log(data[0].numContacts);
- var ctx = document.getElementById("myChart");
- var myChart = new Chart(ctx, {
- type: 'bar',
- data: {
- labels:
- [names[0], names[1], names[2],names[3],names[4],
- names[5],names[6],names[7], names[8],names[9]],
- datasets: [{
- label: 'No. Of Contacts in each account',
- data: [data[0].numContacts,data[1].numContacts,
- data[2].numContacts,data[3].numContacts,
- data[4].numContacts,data[5].numContacts,data[6].numContacts,
- data[7].numContacts,data[8].numContacts,data[9].numContacts],
- backgroundColor: [
- 'rgba(255, 99, 132, 0.2)',
- 'rgba(54, 162, 235, 0.2)',
- 'rgba(255, 206, 86, 0.2)',
- 'rgba(75, 192, 192, 0.2)',
- 'rgba(153, 102, 255, 0.2)',
- 'rgba(255, 159, 64, 0.2)',
- 'rgba(255, 99, 132, 0.2)',
- 'rgba(54, 162, 235, 0.2)',
- 'rgba(255, 206, 86, 0.2)',
- 'rgba(75, 192, 192, 0.2)'
- ]
- }]
- },
- options: {
- responsive: false,
- scales: {
- xAxes: [{
- ticks: {
- maxRotation: 90,
- minRotation: 80
- }
- }],
- yAxes: [{
- ticks: {
- beginAtZero: true
- }
- }]
- }
- }
- });
- });
- </script>
- </apex:page>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement