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

Symfony PHP Discussion :

Cannot read property 'count' of undefined [Symfony3 ] Google charts Bundle [3.x]


Sujet :

Symfony PHP

  1. #1
    Nouveau membre du Club
    Femme Profil pro
    Inscrit en
    Juillet 2013
    Messages
    44
    Détails du profil
    Informations personnelles :
    Sexe : Femme

    Informations forums :
    Inscription : Juillet 2013
    Messages : 44
    Points : 25
    Points
    25
    Par défaut Cannot read property 'count' of undefined [Symfony3 ] Google charts Bundle
    Salut les amis ! Je veux utiliser Google charts Bundle pour générer mes graphes ! donc je suis le lien suivant ! Je veux générer une comboChart qui contient 2 bars (Actions déclarés et Actions Non cloturées ) avec une ligne qui montre le taux de retard . On me retourne l'erreur suivante : Cannot read property 'count' of undefined Voilà mon code :
    chartdata.php
    Code : 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
    public function dataActionsRetardByWeek()
        {
    		$actionsCreats = $this->em->getRepository('ActionActionBundle:Action')->ActionsCreatByWeek();
    		$actionsRetards = $this->em->getRepository('ActionActionBundle:Action')->ActionsRetardByWeek();
     
    		$arrayToDataTable[] = ['Semaine', 'Actions Ouvertes', ['role' => 'tooltip'], 'Actions en Retard',['role' => 'tooltip'], 'Taux de Retard',['role' => 'tooltip'] ];
     
    		//$arrayToDataTable[] = ['Semaine', 'Actions Ouvertes', ['role' => 'tooltip'], 'Taux de Retard',['role' => 'tooltip'] ];
     
    		$NombreAction = 0;
    		$NombreActionRetard = 0;
     
    		foreach ($actionsCreats as $actionsCreat) {
     
    			if($NombreAction !=0){
     
    				foreach ($actionsRetards as $actionsRetard) {
     
    					//if($NombreActionRetard !=0){
     
    						$tauxRetard = round(($actionsRetard['nmbreRetard']*100) / $NombreAction, 2);
     
    					//}else{
     
    						//$tauxRetard = 0;
    					//}
    					//$NombreActionRetard = $actionsRetard['nmbreRetard'];
    					$NombreAction = $actionsCreat['nmbreAction'];
    					$tooltipTaux ="Taux de Retard %";
    					$tooltipRetard=$this->formatnmbreRetard($actionsRetard['nmbreRetard']) . 'Actions';//"Actions en retard";
    					$tooltipCreat=$this->formatnmbreAction($actionsCreat['nmbreAction']) . 'Actions';//"Actions ouvertes";
    					$arrayToDataTable[] = [$actionsCreat['week'], intval($actionsCreat['nmbreAction']), $tooltipCreat, intval($actionsRetard['nmbreRetard']), $tooltipRetard, $tauxRetard, $tooltipTaux];
    				}
    			}else{
     
    				$tauxRetard = 0;
    			}
    		}
    		return $arrayToDataTable;
    	}
    data.php

    Code : 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
    public function ActionsRetardByWeek()
        {
            $arrayToDataTable = $this->chartData->dataActionsRetardByWeek();
     
            $chart = new ComboChart();
            $chart->getData()->setArrayToDataTable($arrayToDataTable);
            $chart->getOptions()->getAnimation()->setStartup(self::ANIMATION_STARTUP);
            $chart->getOptions()->getAnimation()->setDuration(self::ANIMATION_DURATION);
            $chart->getOptions()->getChartArea()->setHeight(self::CHART_AREA_HEIGHT);
            $chart->getOptions()->getChartArea()->setWidth(self::CHART_AREA_WIDTH);
     
            $vAxisAction = new VAxis();
            $vAxisAction->setTitle('Actions');
            $vAxisTaux = new VAxis();
            $vAxisTaux->setTitle('Taux de Retard %');
            $chart->getOptions()->setVAxes(json_encode ([$vAxisAction,$vAxisTaux],JSON_NUMERIC_CHECK));
            //$chart->getOptions()->setVAxes([$vAxisAction,$vAxisTaux]);
     
     
            /**Actions ouvertes*/
     
            $seriesAction = new \CMEN\GoogleChartsBundle\GoogleCharts\Options\ComboChart\Series();
            $seriesAction->setType('bars');
            $seriesAction->setTargetAxisIndex(0);
            $seriesAction->setColor('#5858FA');
     
            /**Actions en retard**/
     
            $seriesRetard = new \CMEN\GoogleChartsBundle\GoogleCharts\Options\ComboChart\Series();
            $seriesRetard->setType('bars');
            $seriesRetard->setTargetAxisIndex(1);
            $seriesRetard->setColor('#C64141');
     
            /** Taux de retard**/
     
            $seriesTaux = new \CMEN\GoogleChartsBundle\GoogleCharts\Options\ComboChart\Series();
            $seriesTaux->setType('line');
            $seriesTaux->setTargetAxisIndex(2);
            $seriesTaux->setColor('yellow');
     
            $chart->getOptions()->setSeries([$seriesAction,$seriesRetard,$seriesTaux]);
     
            $chart->getOptions()->getHAxis()->setTitle('Semaine');
     
            return $chart;
        }
    Ca fait 2 jrs que je bloque sur cette erreur :'( :'(

  2. #2
    Membre émérite

    Profil pro
    Inscrit en
    Mai 2008
    Messages
    1 576
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 1 576
    Points : 2 440
    Points
    2 440
    Par défaut
    Il faut que tu indiques quelle ligne déclenche cette erreur, autrement personne ne peut t'aider.

  3. #3
    Nouveau membre du Club
    Femme Profil pro
    Inscrit en
    Juillet 2013
    Messages
    44
    Détails du profil
    Informations personnelles :
    Sexe : Femme

    Informations forums :
    Inscription : Juillet 2013
    Messages : 44
    Points : 25
    Points
    25
    Par défaut
    Merci Tsilefy Pour ta réponse ! En fait je trouve rien comme erreur dans mon fichier log ! ni lorsque j'inspecte ma page !! Je ne sais pas comment je peux avoir la ligne qui cause cette erreur.
    Voilà le code Javascript que retourne ma page :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    <script type="text/javascript">
            google.charts.load('current', {packages:['corechart']});google.charts.setOnLoadCallback(drawChart953dc480a77eb7b611c71c90aedce116);
                function drawChart953dc480a77eb7b611c71c90aedce116() {var chartDiv_graph_retard = new google.visualization.ComboChart(document.getElementById("div_graph_retard"));var dataChartDiv_graph_retard = new google.visualization.arrayToDataTable([["Semaine", "Actions Ouvertes", {"role":"tooltip"}, "Actions en Retard", {"role":"tooltip"}, "Taux de Retard", {"role":"tooltip"}]], false);var optionsChartDiv_graph_retard = {"animation":{"startup":true,"duration":1000},"hAxis":{"title":"Semaine"},"vAxes":"[{},{}]","series":[{"type":"bars","targetAxisIndex":0,"color":"#5858FA"},{"type":"bars","targetAxisIndex":1,"color":"#C64141"},{"type":"line","targetAxisIndex":2,"color":"yellow"}],"chartArea":{"height":"80%","width":"80%"}};
    chartDiv_graph_retard.draw(dataChartDiv_graph_retard, optionsChartDiv_graph_retard);}
        </script>

  4. #4
    Membre émérite

    Profil pro
    Inscrit en
    Mai 2008
    Messages
    1 576
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 1 576
    Points : 2 440
    Points
    2 440
    Par défaut
    Tu as des fautes d'orthographe dans ton code et des erreurs dans ce code:
    c'est vAxis, pas vAxes, et la valeur devrait être un objet, donc:

  5. #5
    Nouveau membre du Club
    Femme Profil pro
    Inscrit en
    Juillet 2013
    Messages
    44
    Détails du profil
    Informations personnelles :
    Sexe : Femme

    Informations forums :
    Inscription : Juillet 2013
    Messages : 44
    Points : 25
    Points
    25
    Par défaut
    Merci Tsilfey pour ton interêt ! excuses moi mais j'ai pas compris où je dois modifier mon code ! Ce code Javascript est généré automatiquement dans le code source de la page chrome ! Tu peux m'expliquer davantage ? Merci

  6. #6
    Membre émérite

    Profil pro
    Inscrit en
    Mai 2008
    Messages
    1 576
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 1 576
    Points : 2 440
    Points
    2 440
    Par défaut
    Je n'ai pas le temps d'investiguer là, mais le problème se situe dans ces lignes:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    $chart->getOptions()->setVAxes(json_encode ([$vAxisAction,$vAxisTaux],JSON_NUMERIC_CHECK));
            //$chart->getOptions()->setVAxes([$vAxisAction,$vAxisTaux]);
    Regarde la doc et ce qu'ils recommendent.

  7. #7
    Nouveau membre du Club
    Femme Profil pro
    Inscrit en
    Juillet 2013
    Messages
    44
    Détails du profil
    Informations personnelles :
    Sexe : Femme

    Informations forums :
    Inscription : Juillet 2013
    Messages : 44
    Points : 25
    Points
    25
    Par défaut
    En fait json_encode permet de rendre un type string en numeric ! Lorsque j'enleve le json_encode je reçoit l'erreur suivante : Data column(s) for axis #0 cannot be of type string

  8. #8
    Membre émérite

    Profil pro
    Inscrit en
    Mai 2008
    Messages
    1 576
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 1 576
    Points : 2 440
    Points
    2 440
    Par défaut
    La ligne correct est:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    $chart->getOptions()->setVAxes([$vAxisAction,$vAxisTaux]);
    Tu ne dois pas utiliser json_encode pour cette ligne. Si le résultat est un string, c'est qu'il y a une mauvaise configuration quelque part. Révise tout, et à la place de
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    $arrayToDataTable = $this->chartData->dataActionsRetardByWeek();
    Utilise un tableau codé en dur, juste pour voir si ça marche ou pas.

    Ex (tiré de la doc):
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    $data[] = ['Year', 'Income', ['role' => 'tooltip'], 'Cost', ['role' => 'tooltip'], 'Evolution', ['role' => 'tooltip']];
    $data[] = ['2012', 106756, '106 756 €', 67450, '67 450 €', 12.54, '12.54 %'];
    $data[] = ['2013', 153765, '153 765 €', 82345, '82 345 €', 18.12, '18.12 %'];
    $data[] = ['2014', 198450, '198 450 €', 73984, '73 984 €', 8.68, '8.68 %'];
     
    $chart = new ComboChart();
    $chart->getData()->setArrayToDataTable($data);
    Et regarde (et poste ici) le javascript ainsi généré.

  9. #9
    Nouveau membre du Club
    Femme Profil pro
    Inscrit en
    Juillet 2013
    Messages
    44
    Détails du profil
    Informations personnelles :
    Sexe : Femme

    Informations forums :
    Inscription : Juillet 2013
    Messages : 44
    Points : 25
    Points
    25
    Par défaut
    Bonjour Tsilefy ! J'ai fait comme tu as demandé ! et ça marché parfaitement ! voilà le code javascript généré :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     <script type="text/javascript">
            google.charts.load('current', {packages:['corechart']});google.charts.setOnLoadCallback(drawChart953dc480a77eb7b611c71c90aedce116);
                function drawChart953dc480a77eb7b611c71c90aedce116() {var chartDiv_graph_retard = new google.visualization.ComboChart(document.getElementById("div_graph_retard"));var dataChartDiv_graph_retard = new google.visualization.arrayToDataTable([["Year", "Income", {"role":"tooltip"}, "Cost", {"role":"tooltip"}, "Evolution", {"role":"tooltip"}], ["2012", 106756, "106 756 \u20ac", 67450, "67 450 \u20ac", 12.54, "12.54 %"], ["2013", 153765, "153 765 \u20ac", 82345, "82 345 \u20ac", 18.12, "18.12 %"], ["2014", 198450, "198 450 \u20ac", 73984, "73 984 \u20ac", 8.68, "8.68 %"]], false);var optionsChartDiv_graph_retard = {"animation":{"startup":true,"duration":1000},"hAxis":{"title":"Semaine"},"vAxes":[{"title":"Actions"},{"title":"Taux de Retard %"}],"series":[{"type":"bars","targetAxisIndex":0,"color":"#5858FA"},{"type":"bars","targetAxisIndex":0,"color":"#C64141"},{"type":"line","targetAxisIndex":1,"color":"yellow"}],"chartArea":{"height":"80%","width":"80%"},"title":"Taux de retard des actions"};
    chartDiv_graph_retard.draw(dataChartDiv_graph_retard, optionsChartDiv_graph_retard);}
        </script>
    je ne sais pas qu'est ce que je dois modifier pour que ça marche pour les données de ma BD

  10. #10
    Nouveau membre du Club
    Femme Profil pro
    Inscrit en
    Juillet 2013
    Messages
    44
    Détails du profil
    Informations personnelles :
    Sexe : Femme

    Informations forums :
    Inscription : Juillet 2013
    Messages : 44
    Points : 25
    Points
    25
    Par défaut
    Personne ne peut m'aider içi ??

  11. #11
    Membre éprouvé
    Homme Profil pro
    Développeur Web
    Inscrit en
    Novembre 2013
    Messages
    739
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Novembre 2013
    Messages : 739
    Points : 1 022
    Points
    1 022
    Par défaut
    tu dois créer un tableau $data avec tes données sauf qu'il dois être de mémé structure avec le tableau statique que tu as utilisé avec succès.

  12. #12
    Nouveau membre du Club
    Femme Profil pro
    Inscrit en
    Juillet 2013
    Messages
    44
    Détails du profil
    Informations personnelles :
    Sexe : Femme

    Informations forums :
    Inscription : Juillet 2013
    Messages : 44
    Points : 25
    Points
    25
    Par défaut
    C'est exactement ce que j'ai fait Mehrez ! C la même structure que les données avec lesquelles j'ai testé ! Mais il me retourne Data column(s) for axis #0 cannot be of type string Alors que j'ai que les types number pas de String

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

Discussions similaires

  1. Réponses: 3
    Dernier message: 01/06/2016, 21h45
  2. Erreur : TypeError: Cannot read property 'test' of undefined
    Par deathness dans le forum AngularJS
    Réponses: 1
    Dernier message: 11/05/2016, 11h42
  3. Réponses: 3
    Dernier message: 30/05/2015, 13h08
  4. [V8] Importation csv Error Cannot read property '1' of undefined
    Par vernetk dans le forum Odoo (ex-OpenERP)
    Réponses: 1
    Dernier message: 11/02/2015, 17h36
  5. Réponses: 15
    Dernier message: 15/06/2013, 02h11

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