如何在图表中隐藏值为零的数据标签。 js

时间:2018-06-22 13:26:48

标签: javascript php chart.js

我在下面的图表中创建了一些值为0的结果,我想隐藏仅包含0值的标签。我是用PHP创建的,但是我隐藏了值,而不是标签本身。例如,我有标签

  

['6/1/2018'。'6/2/2018','6/3/2018'等...。]

并且标签6/2/2018拥有0个值,我想将其隐藏

var barChartData1 = {
    labels: [
    <?php
    $arraylenght = count($month);
    for($x = 0; $x < $arraylenght; $x++) {
        echo '"' . $month[$x] . '"' . ',' ;
    }
    ?>
    ],
    datasets: [
        {
            type: 'line',
            label: 'Nps',
            borderColor: 'red',
            borderWidth: 1,
            fill: false,
            data: [
                <?php
                foreach ($month  as $date ){
                    $e_t = "select * from nps where date = '$date' and team_id ='$id'"; // to select total rows             
                    $e_p = "select * from nps where team_id= '$id' and nps_rating >= 9 and date = '$date' "; // select promoter
                    $e_d = "select * from nps where team_id ='$id' and nps_rating <= 6 and date = '$date' "; // select dertactor
                    $e_tq = $cont->query($e_t); 
                    $e_pq = $cont->query($e_p); 
                    $e_dq = $cont-> query ($e_d);

                    if ($e_tq->num_rows == 0){
                        $e_eq = 0;
                        //continue;
                    }else{
                        $e_eq = (($e_pq->num_rows - $e_dq->num_rows) / $e_tq->num_rows) * 100 ; // get result of nps
                    }
                        echo round($e_eq) . ',';
                    }
                ?>
                ]

0 个答案:

没有答案