Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. public with sharing class lwcLifetimeSpendingController {
  2.  
  3.  
  4. @AuraEnabled (cacheable=true)
  5. public static List<AggregateResult> getAccountLifetimeSpending(){
  6. return [SELECT SUM(Service_Amount__c) Service, SUM(Subscription_Booking__c) Subscription SUM(Renewal_Amount_Xactly__c) Renewal FROM Opportunity WHERE AccountId = '0018000001G9dZUAAZ' and isClosed=true and isWon=true];
  7. }
  8.  
  9. @wire(getAccountLifetimeSpending) lifetimeAggregateResult({error,data}) {
  10. if (data) {
  11. this.lifetimeAggResult = data;
  12. console.log('this.lifetimeAggResult: ' + this.lifetimeAggResult[0].Service);
  13. this.serviceAmount = this.lifetimeAggResult[0].Service;
  14. this.subcriptionAmount = this.lifetimeAggResult[0].Subscription;
  15. this.error = undefined;
  16. } else if (error) {
  17. this.lifetimeAggResult = undefined;
  18. this.error = error;
  19. console.log('Error: ' + this.error);
  20. }
  21. }
  22. chart;
  23. chartjsInitialized = false;
  24.  
  25. config = {
  26. //type: 'doughnut',
  27. type: 'bar',
  28. data: {
  29. datasets: [
  30. {
  31. data: [
  32. this.serviceAmount,
  33. this.subcriptionAmount
  34. ],
  35. backgroundColor: [
  36. 'rgb(255, 99, 132)',
  37. 'rgb(255, 159, 64)',
  38. 'rgb(255, 205, 86)',
  39. 'rgb(75, 192, 192)',
  40. 'rgb(54, 162, 235)'
  41. ],
  42. label: 'Dataset 1'
  43. }
  44. ],
  45. labels: ['Service', 'Subscription', 'Private Training', 'Public Training', 'Renewal']
  46. },
  47. options: {
  48. responsive: true,
  49. legend: {
  50. position: 'right'
  51. },
  52. animation: {
  53. animateScale: true,
  54. animateRotate: true
  55. }
  56. }
  57. };
  58.  
  59. renderedCallback() {
  60. if (this.chartjsInitialized) {
  61. return;
  62. }
  63. this.chartjsInitialized = true;
  64.  
  65. loadScript(this, chartjs)
  66. .then(() => {
  67. const ctx = this.template
  68. .querySelector('canvas.donut')
  69. .getContext('2d');
  70. this.chart = new window.Chart(ctx, this.config);
  71. })
  72. .catch(error => {
  73. this.error = error;
  74. });
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement