Bonjour à tous, le code est super long pour cette partie, je vais uniquement mettre ce qui est utile à la compréhension.

Chart Type : ng-apexcharts
Le besoin :
Au chargement de la page : Afficher un graphique vide ou ne pas l'afficher
Après la récupération de la data et son traitement, mettre à jour ou initialiser le graphique pour y afficher la date.

Actuellement :
Tous les imports nécessaires aux graphiques sont OK.
Le graphique fonctionne avec des valeurs hardcodées.
Le code de génération actuel provient d'un template.
Le traitement de la data est fait, les variables sont prêtes et la data est correctement récupérée.

Le problème :
Je n'arrive pas à générer ce graphique avec les données issues du traitement après que la data ait été récupérée, j'ai des erreurs de constructeur au niveau du ViewChild si j'essaie de déplacer ce qui est dans le constructeur dans une fonction.

Merci pour l'aide !

Le code dashboard.component.html :

Code html : Sélectionner tout - Visualiser dans une fenêtre à part
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
<div fxLayout="row wrap">
    <div fxFlex.gt-lg="100" fxFlex.gt-md="100" fxFlex.gt-xs="100" fxFlex="100">
        <mat-card>
            <mat-card-content>
                <mat-card-title>Titre</mat-card-title>
                <mat-card-subtitle>Sous titre</mat-card-subtitle>
                <div id="newsletter-chart">
                    <apx-chart [series]="newsletterchartOptions.series" [chart]="newsletterchartOptions.chart"
                        [xaxis]="newsletterchartOptions.xaxis" [stroke]="newsletterchartOptions.stroke"
                        [tooltip]="newsletterchartOptions.tooltip" [dataLabels]="newsletterchartOptions.dataLabels"
                        [legend]="newsletterchartOptions.legend" [colors]="newsletterchartOptions.colors"
                        [markers]="newsletterchartOptions.markers">
                    </apx-chart>
                </div>
                <!-- <div class="linearea" style="height:360px;">
                    <x-chartist class="" [data]="lineChart1.data" [type]="lineChart1.type"
                        [options]="lineChart1.options" [responsiveOptions]="lineChart1.responsiveOptions"
                        [events]="lineChart1.events"> </x-chartist>
                </div> -->
                <ul class="list-inline text-center p-t-10">
                    <li>
                        <h6 class="text-muted text-info m-0">
                            <i class="fa fa-circle font-10 m-r-10 "></i>Sent</h6>
                    </li>
                    <li>
                        <h6 class="text-muted  text-success  m-0">
                            <i class="fa fa-circle font-10 m-r-10"></i>Clicked</h6>
                    </li>
                </ul>
            </mat-card-content>
        </mat-card>
    </div>
 
</div>

Le code dashboard.component.ts :

Code angular : Sélectionner tout - Visualiser dans une fenêtre à part
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
 
import { Component, OnInit, Injectable, ViewChild, ChangeDetectorRef } from '@angular/core';
import { RestApiService } from '../../shared/rest-api.service';
import * as Chartist from 'chartist';
import { ChartType, ChartEvent } from 'ng-chartist';
...
...
export interface Chart {
    type: ChartType;
    data: Chartist.IChartistData;
    options?: any;
    responsiveOptions?: any;
    events?: ChartEvent;
}
...
...
ProjectZeroMonthAgo = 0;
ProjectOneMonthAgo =  0;
...
...
   @ViewChild('visitor-chart') chart2: ChartComponent = Object.create(null);
    public VisitorChartOptions: Partial<VisitorChartOptions>;
 
    @ViewChild('newsletter-chart') chart3: ChartComponent = Object.create(null);
    public newsletterchartOptions: Partial<newsletterchartOptions>;
 
    ngOnInit() {     
        this.getNamespaces();
    }
 
getNamespaces(){
        this.dataService.getAllNameSpaces().subscribe((res)=>{
            this.datamoi = res;
            this.Traitement();            
        });
    }
 
Traitement(){       
 
        var ZeroMonthAgo = convertDate(new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate()));
         ...
         ...
 
        console.log("Ma data est dans plusieurs variables, dont celle-ci " + this.ProjectZeroMonthAgo )
}
 
 
constructor(private dataService: RestApiService) {
 
        this.VisitorChartOptions = {
            series: [45, 15, 27, 18],
            chart: {
                type: 'donut',
                height: 290
            },
            plotOptions: {
                pie: {
                    donut: {
                        size: '80px'
                    }
                }
            },
            tooltip: {
                fillSeriesColor: false,
            },
            dataLabels: {
                enabled: false,
            },
            stroke: {
                width: 0
            },
            legend: {
                show: false,
            },
            labels: ['Mobile', 'Tablet', 'Desktop', 'Other'],
            colors: ['#1e88e5', '#26c6da', '#745af2', '#eceff1'],
            responsive: [
                {
                    breakpoint: 480,
                    options: {
                        chart: {
                            width: 200
                        }
                    }
                }
            ]
        };
        this.newsletterchartOptions = {
            series: [
                {
                    name: 'Clicked',
                    data: [this.ProjectZeroMonthAgo, this.ProjectOneMonthAgo, 15000, 1000, 1500, 9000, 3000, 0, 5000, 15000, 8000, 1500, 9000, 3000, 0] // Mes variables ne prennent pas la data souhaitée, mais celle de l'initialisation.
                },
                {
                    name: 'Sent',
                    data: [100, 3000, 5000, 2000, 1600, 1000, 5000, 0, 3000, 5000, 2000, 8000, 1000, 5000, 0]
                }
            ],
            chart: {
                height: 290,
                type: 'area'
            },
            dataLabels: {
                enabled: false
            },
            markers: {
                size: 3,
            },
            stroke: {
                curve: 'smooth',
                width: '2'
            },
            colors: ['#26c6da', '#1e88e5'],
            legend: {
                show: false,
            },
            grid: {
                borderColor: 'rgba(0,0,0,.2)',
                strokeDashArray: 3,
                yaxis: {
                    lines: {
                        show: true
                    }
                },
                xaxis: {
                    lines: {
                        show: true
                    }
                },
            },
            xaxis: {
                type: 'category',
                categories: [
                    '01/2020',
                    '01/2020',
                    '01/2020',
                    '01/2020',
                    '01/2020',
                    '01/2020',
                    '01/2020',
                    '01/2020',
                    '01/2020',
                    '01/2020',
                    '01/2020',
                    '01/2020',
                    '01/2020'
                ]
            },
            tooltip: {
                x: {
                    format: 'dd/MM/yy HH:mm'
                }
            }
        };
    }
 
 
}