Guest User

Untitled

a guest
Apr 23rd, 2024
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. Code:
  2.  
  3. ```
  4. import { Component, OnInit } from '@angular/core';
  5. import { CommonModule } from '@angular/common';
  6. import { RouterOutlet } from '@angular/router';
  7.  
  8. import { CanvasJSAngularChartsModule } from '@canvasjs/angular-charts';
  9. import { ExpenseService } from '../../service/expenseservice';
  10. import { TotaldebitStatsByCategory } from '../../model/totaldebitstatsbycategory';
  11.  
  12. @Component({
  13. selector: 'app-totaldebitbarchart',
  14. standalone: true,
  15. imports: [
  16. CommonModule, RouterOutlet, CanvasJSAngularChartsModule
  17. ],
  18. providers: [ ExpenseService],
  19. templateUrl: './totaldebitbarchart.component.html',
  20. styleUrl: './totaldebitbarchart.component.css'
  21. })
  22. export class TotaldebitbarchartComponent implements OnInit {
  23. chartOptions: any = {};
  24. totalDebitStatsByCategory = new TotaldebitStatsByCategory();
  25.  
  26. constructor(private expenseService: ExpenseService) {}
  27.  
  28. ngOnInit() {
  29. this.expenseService.getTotalDebitStatsByCategory().subscribe(data => {
  30. this.totalDebitStatsByCategory = data;
  31. this.updateChartOptions();
  32. });
  33. }
  34.  
  35. private updateChartOptions() {
  36. console.log(this.totalDebitStatsByCategory);
  37. console.log(this.totalDebitStatsByCategory.mapToArray());
  38. this.chartOptions = {
  39. title: {
  40. text: "Uitgave per categorie"
  41. },
  42. animationEnabled: true,
  43. axisY: {
  44. includeZero: true,
  45. suffix: "Euro"
  46. },
  47. data: [{
  48. type: "bar",
  49. indexLabel: "{y}",
  50. yValueFormatString: "#,### Euro",
  51. dataPoints: this.totalDebitStatsByCategory.mapToArray()
  52. }]
  53. };
  54. }
  55. }
  56. ```
  57.  
  58. underneath my htlm code:
  59.  
  60. ```
  61. <div>
  62. <canvasjs-chart [options]="chartOptions" [styles]="{width: '100%', height:'360px'}"></canvasjs-chart>
  63. </div>
  64. ```
  65. Underneath my class:
  66.  
  67. ```
  68. export class TotaldebitStatsByCategory {
  69. total: Map<string, BigInt>;
  70.  
  71. constructor() {
  72. this.total = new Map<string, BigInt>();
  73. }
  74.  
  75. mapToArray(): { label: string, y: number }[] {
  76. return Array.from(this.total.entries()).map(([label, y]) => ({ label, y: Number(y) }));
  77. }
  78. }
  79. ```
  80.  
  81.  
  82.  
Advertisement
Add Comment
Please, Sign In to add comment