Question

given this stacked column chart data:

        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
        }
        ?>
        ];

i want to handle alerts given conditions like this (notice the /when-clicked condition goes here/):

        // 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 );
                }
            }

what could be the syntax for the condition?

Was it helpful?

Solution

The condition would be like this:

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

and so on. or use switch

        // 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+")" );               
        }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top