Question

Compte tenu de cette carte de graphique colonnée empilée:

        var chartData = [

        <?php
        foreach($emptyArray as $key => $arrInternal){
            if($key>0){
            ?>, <?php
            }
              ?>
              {
                "position":                     <?php echo json_encode($emptyArray[$key][0][2]); ?>,

                "demand":                       parseInt(<?php echo "'".$emptyArray[$key][0][4]."'"; ?>),
                "crewplanned":                  parseInt(<?php echo "'".$emptyArray[$key][1][4]."'"; ?>),
                "CrewplannedLineup":            parseInt(<?php echo "'".$emptyArray[$key][2][4]."'"; ?>),
                "replacement1":                 parseInt(<?php echo "'".$emptyArray[$key][3][4]."'"; ?>),

                "demandsubdata":                <?php echo json_encode($emptyArray[$key][0][5]); ?>,
                "crewplannedsubdata":           <?php echo json_encode($emptyArray[$key][1][5]); ?>,
                "CrewplannedLineupsubdata":     <?php echo json_encode($emptyArray[$key][2][5]); ?>,
                "replacement1subdata":          <?php echo json_encode($emptyArray[$key][3][5]); ?>
              }
              <?php
        }
        ?>
        ];

Je veux gérer des alertes données des conditions telles que celles-ci (remarquez / quand la condition cliquée va ici /):

        // this method handles chart data click
            function handleClick(event)
            { 
                if (event.item.dataContext.demand /*when-clicked condition goes here*/) {
                  alert(event.item.category + ": " + event.item.values.value + "|"+ event.item.dataContext.demandsubdata );
                }
                else if(event.item.dataContext.crewplanned /*when-clicked condition goes here*/){
                  alert(event.item.category + ": " + event.item.values.value + "|"+ event.item.dataContext.crewplannedsubdata );    
                }
               else if(event.item.dataContext.CrewplannedLineup /*when-clicked condition goes here*/){
                  alert(event.item.category + ": " + event.item.values.value + "|"+ event.item.dataContext.CrewplannedLineupsubdata );
                }
               else if(event.item.dataContext.replacement1 /*when-clicked condition goes here*/){
                  alert(event.item.category + ": " + event.item.values.value + "|"+ event.item.dataContext.replacement1subdata );
                }
            }

Quelle pourrait être la syntaxe de la condition?

Était-ce utile?

La solution

La condition serait comme ceci:

if(event.graph.valueField=="demand")

et ainsi de suite.ou utiliser le commutateur

        // this method handles chart data click
        function handleClick(event)
        {
          var subdata="";
            switch (event.graph.valueField){
              case "demand":            subdata=event.item.dataContext.demandsubdata;            break;
              case "crewplanned":       subdata=event.item.dataContext.crewplannedsubdata;       break;
              case "CrewplannedLineup": subdata=event.item.dataContext.CrewplannedLineupsubdata; break;
              case "replacement1":      subdata=event.item.dataContext.replacement1subdata;      break;
          }
            alert("Find out who are these "+ event.item.values.value +" "+ event.item.category+". Click OK. \n("+ subdata+")" );               
        }

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top