IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Angular Discussion :

Affichage graphique au changement de page


Sujet :

Angular

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Homme Profil pro
    Ingénieur systèmes et réseaux
    Inscrit en
    Novembre 2017
    Messages
    124
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 26
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Ingénieur systèmes et réseaux
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Novembre 2017
    Messages : 124
    Par défaut Affichage graphique au changement de page
    Bonjour à tous

    J'ai sur une page "DashBoard" un graphique de type Bar basé sur "chartjs".
    Lorsque je lance le dashboard, le graphique se dessine sans problème, par contre si je vais sur une autre page et que je revient sur le dashboard, le graphique ne se dessine pas.

    Important : La data est pourtant bien là ! car lorsque je clique sur "ne pas afficher tel ou tel status", le graphique se dessine..
    Je ne peux pas fournir de stackblitz pour ce cas de figure..


    chartjs-bar.component.ts

    Code javascript : 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
    import { AfterViewInit, Component, OnDestroy, OnInit } from '@angular/core';
    import { NbThemeService, NbColorHelper } from '@nebular/theme';
    import { RestApiService } from '../../../shared/rest-api/rest-api.service';
     
    @Component({
      selector: 'ngx-chartjs-bar',
      template: `
        <chart type="bar" [data]="data" [options]="options"></chart>
      `,
    })
    export class ChartjsBarComponent implements OnDestroy, OnInit, AfterViewInit {
      data: any;
      options: any;
      themeSubscription: any;
     
      getHistoryOfContainers(): any{
        this.dataService.getHistoryOfContainerDeployment().subscribe((res)=>{
          this.data.labels = res.labels;     
          this.data.datasets[0].data = res.running;
          this.data.datasets[1].data = res.paused;
          this.data.datasets[2].data = res.stopped;
          this.data.datasets[3].data = res.failed;
        });    
      }
     
      ngOnInit() {
        console.log("passé"); // s'affiche à chaque chargement de page.
        this.getHistoryOfContainers();
      }
     
      constructor(private theme: NbThemeService, private dataService: RestApiService) {    
     
        this.themeSubscription = this.theme.getJsTheme().subscribe(config => {
     
          const colors: any = config.variables;
          const chartjs: any = config.variables.chartjs;      
     
          this.data = {
            labels: ['Loading...','Loading...','Loading...','Loading...','Loading...','Loading...','Loading...', 'Loading...', 'Loading...', 'Loading...', 'Loading...', 'Loading...'],
            datasets: [{
              data: [0,0,0,0,0,0,0,0,0,0,0,0],
              label: 'Running',
              backgroundColor: NbColorHelper.hexToRgbA(colors.success, 0.8),
            }, {
              data: [0,0,0,0,0,0,0,0,0,0,0,0],
              label: 'Paused',
              backgroundColor: NbColorHelper.hexToRgbA(colors.warning, 0.8),
            },
            {
              data: [0,0,0,0,0,0,0,0,0,0,0,0],
              label: 'Stopped',
              backgroundColor: NbColorHelper.hexToRgbA(colors.dangerLight, 0.8),
            },
            {
              data: [0,0,0,0,0,0,0,0,0,0,0,0],
              label: 'Failed',
              backgroundColor: NbColorHelper.hexToRgbA(colors.danger, 0.8),
            }],
          };
     
          this.options = {
            maintainAspectRatio: false,
            responsive: true,
            legend: {
              labels: {
                fontColor: chartjs.textColor,
              },
            },
            scales: {
              xAxes: [
                {
                  gridLines: {
                    display: false,
                    color: chartjs.axisLineColor,
                  },
                  ticks: {
                    fontColor: chartjs.textColor,
                  },
                },
              ],
              yAxes: [
                {
                  gridLines: {
                    display: true,
                    color: chartjs.axisLineColor,
                  },
                  ticks: {
                    fontColor: chartjs.textColor,
                    beginAtZero: true,
                    callback: function(value) {if (value % 1 === 0) {return value;}}
                  },
                },
              ],
            },
          };
        });
      }
     
      ngOnDestroy(): void {
        this.themeSubscription.unsubscribe();
      }
    }

    chartjs.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
    <div class="row">
      <div class="col-lg-12">
        <nb-card>
          <nb-card-header>
            <i class="ion-cube"></i>
            <span class="title"> Evolution du nombre de conteneurs au cours du temps</span>
          </nb-card-header>
          <nb-card-body>
            <ngx-chartjs-bar></ngx-chartjs-bar>
          </nb-card-body>
        </nb-card>
      </div>
    </div>


    chartjs.component.ts

    Code javascript : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    import { Component } from '@angular/core';
     
    @Component({
      selector: 'ngx-chartjs',
      styleUrls: ['./chartjs.component.scss'],
      templateUrl: './chartjs.component.html',
    })
    export class ChartjsComponent {}



    Si jamais vous avez une idée d'ou ça peut venir
    Images attachées Images attachées  

  2. #2
    Membre très actif
    Homme Profil pro
    Développeur Web
    Inscrit en
    Janvier 2019
    Messages
    707
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Janvier 2019
    Messages : 707
    Par défaut
    ce que tu as mis dans le constructor met le dans ngOnInit()

  3. #3
    Membre confirmé
    Homme Profil pro
    Ingénieur systèmes et réseaux
    Inscrit en
    Novembre 2017
    Messages
    124
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 26
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Ingénieur systèmes et réseaux
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Novembre 2017
    Messages : 124
    Par défaut
    Résultat strictement identique

    Code javascript : 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
     
     
    import { AfterViewInit, Component, OnDestroy, OnInit } from '@angular/core';
    import { NbThemeService, NbColorHelper } from '@nebular/theme';
    import { RestApiService } from '../../../shared/rest-api/rest-api.service';
     
    @Component({
      selector: 'ngx-chartjs-bar',
      template: `
        <chart type="bar" [data]="data" [options]="options"></chart>
      `,
    })
    export class ChartjsBarComponent implements OnDestroy, OnInit, AfterViewInit {
      data: any;
      options: any;
      themeSubscription: any;
     
      getHistoryOfContainers(): any{
        this.dataService.getHistoryOfContainerDeployment().subscribe((res)=>{
          this.data.labels = res.labels;     
          this.data.datasets[0].data = res.running;
          this.data.datasets[1].data = res.paused;
          this.data.datasets[2].data = res.stopped;
          this.data.datasets[3].data = res.failed;
        });    
      }
     
      ngOnInit() {
        console.log("passé"); // s'affiche à chaque chargement de page.
     
     
        this.themeSubscription = this.theme.getJsTheme().subscribe(config => {
     
          const colors: any = config.variables;
          const chartjs: any = config.variables.chartjs;      
     
          this.data = {
            labels: ['Loading...','Loading...','Loading...','Loading...','Loading...','Loading...','Loading...', 'Loading...', 'Loading...', 'Loading...', 'Loading...', 'Loading...'],
            datasets: [{
              data: [0,0,0,0,0,0,0,0,0,0,0,0],
              label: 'Running',
              backgroundColor: NbColorHelper.hexToRgbA(colors.success, 0.8),
            }, {
              data: [0,0,0,0,0,0,0,0,0,0,0,0],
              label: 'Paused',
              backgroundColor: NbColorHelper.hexToRgbA(colors.warning, 0.8),
            },
            {
              data: [0,0,0,0,0,0,0,0,0,0,0,0],
              label: 'Stopped',
              backgroundColor: NbColorHelper.hexToRgbA(colors.dangerLight, 0.8),
            },
            {
              data: [0,0,0,0,0,0,0,0,0,0,0,0],
              label: 'Failed',
              backgroundColor: NbColorHelper.hexToRgbA(colors.danger, 0.8),
            }],
          };
     
          this.options = {
            maintainAspectRatio: false,
            responsive: true,
            legend: {
              labels: {
                fontColor: chartjs.textColor,
              },
            },
            scales: {
              xAxes: [
                {
                  gridLines: {
                    display: false,
                    color: chartjs.axisLineColor,
                  },
                  ticks: {
                    fontColor: chartjs.textColor,
                  },
                },
              ],
              yAxes: [
                {
                  gridLines: {
                    display: true,
                    color: chartjs.axisLineColor,
                  },
                  ticks: {
                    fontColor: chartjs.textColor,
                    beginAtZero: true,
                    callback: function(value) {if (value % 1 === 0) {return value;}}
                  },
                },
              ],
            },
          };
        });
     
        this.getHistoryOfContainers();
      }
     
      constructor(private theme: NbThemeService, private dataService: RestApiService) {    
     
     
      }
     
      ngOnDestroy(): void {
        this.themeSubscription.unsubscribe();
      }
    }

  4. #4
    Membre confirmé
    Homme Profil pro
    Ingénieur systèmes et réseaux
    Inscrit en
    Novembre 2017
    Messages
    124
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 26
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Ingénieur systèmes et réseaux
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Novembre 2017
    Messages : 124
    Par défaut
    Après tests, le problème se produit uniquement si la data provient de l'API. Le problème n'apparait pas avec de la data locale .
    En mettant par example : data: [1,0,0,0,0,0,0,0,0,0,0,0],
    Il y a toujours de la data qui s'affiche au load de la page

    EDIT : EN plus de ça, lors du changement de couleur du theme, la data disparait tout simplement..

  5. #5
    Membre très actif
    Homme Profil pro
    Développeur Web
    Inscrit en
    Janvier 2019
    Messages
    707
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Janvier 2019
    Messages : 707
    Par défaut
    est ce que sur chartjs il existe une fonction : refresh ou reload ou reset ou init ....
    pour indiquer à chartjs de rafraichir le graphique à la fin de la récupération des données via l'API


    peut être
    https://www.chartjs.org/docs/latest/...api.html#reset

  6. #6
    Membre confirmé
    Homme Profil pro
    Ingénieur systèmes et réseaux
    Inscrit en
    Novembre 2017
    Messages
    124
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 26
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Ingénieur systèmes et réseaux
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Novembre 2017
    Messages : 124
    Par défaut
    Oui elle existe cette fonction, mais je ne vois pas du tout comment l'appliquer dans mon cas..
    https://www.chartjs.org/docs/latest/...s/updates.html


    Le problème d'affichage et de changement de theme à pour cause ce truc d'update, la data de base se load bien..

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 0
    Dernier message: 13/04/2010, 18h24
  2. Problème affichage graphiques
    Par hide974 dans le forum Excel
    Réponses: 1
    Dernier message: 04/02/2010, 08h38
  3. problème affichage graphique
    Par nuxia dans le forum RedHat / CentOS / Fedora
    Réponses: 3
    Dernier message: 22/12/2008, 23h36
  4. Réponses: 1
    Dernier message: 22/06/2007, 13h42
  5. Réponses: 2
    Dernier message: 15/02/2007, 11h32

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo