An image of the two pie charts and empty cards
我不想显示空卡,因为它没有数据。我已经检查过我的SQL查询,但是似乎没有问题。我认为问题出在if(...)。您能帮我解决这个问题吗?这是我的代码:
在我看来:
<?php
if(empty($js11))
{
echo '';
} else {
$ht='';
$ht.='<div class="col-12 col-sm-12 col-md-12 col-lg-12">';
$ht.='<div class="ibox float-e-margins">';
$ht.='<div class="ibox-title">';
$ht.='<h5>by Quantity</h5>';
$ht.='</div>';
$ht.='<div class="ibox-content" style="padding-right: 8px;padding-left: 8px;">';
$ht.='<div>';
$ht.='<div id="apartment" height="700" width="700" style="position: fixed;"></div>';
$ht.='</div>';
$ht.='</div>';
$ht.='</div>';
$ht.='</div>';
echo $ht;
}
?>
<?php
if(empty($js9))
{
echo '';
} else {
$hts='';
$hts.='<div class="col-12 col-sm-12 col-md-12 col-lg-12">';
$hts.='<div class="ibox float-e-margins">';
$hts.='<div class="ibox-title">';
$hts.='<h5>Landed by Quantity</h5>';
$hts.='</div>';
$hts.='<div class="ibox-content" style="padding-right: 8px;padding-left: 8px;">';
$hts.='<div>';
$hts.='<div id="landed" height="700" width="700" style="position: fixed;"></div>';
$hts.='</div>';
$hts.='</div>';
$hts.='</div>';
$hts.='</div>';
echo $hts;
}
?>
答案 0 :(得分:0)
解决了,如果我只想显示包含任何数据的卡,则只需在控制器上添加if(!empty($data)){...}
。
这是代码:
$jscript11 = '';
if(!empty($dt9)){
$bgColor = '"#2fb4ed","#ba68c8","#33e0ff","#0fe07f","#ffb74d","#4caf50","#ff7043"';
$jdata11= '';
$jdata12='';
$jcolor= '';
// $jjum11= '';
foreach ($apt as $key => $row) {
$qty = ($row->sales_qty / $row->total_sales_qty) * 100;
$qty = number_format($qty, 2);
$qty_unit = $row->sales_qty;
$qtyamt = ($row->sales_amt / $row->total_sales_amt) * 100;
$qtyamt = number_format($qtyamt, 2);
$qtyAmt = $row->sales_amt;
$p11 = '["'.$row->payment_descs.'",'.$qty_unit.']';
$p12 = '["'.$row->payment_descs.'",'.$qtyAmt.']';
$c1 = $bgColor;
$jdata11.= $p11.',';
$jcolor.= $c1.',';
$jdata12.= $p12.',';
}
$jdata11=substr($jdata11,0,-1);
$jcolor=substr($jcolor,0,-1);
$jdata12=substr($jdata12,0,-1);
$jscript11.='var chart1 = c3.generate({bindto: "#paymentaptqty",padding:
{bottom: 20,top:10}, data: {';
$jscript11.=' columns: [ '.$jdata11.'], ';
$jscript11.=' type : "pie", ';
$jscript11.=' colors :['.$jcolor.'] ';
$jscript11.=' }, ';
// $jscript11.=' size: { ';
// $jscript11.=' width: 300, ';
// $jscript11.=' height: 300, ';
// $jscript11.=' }, ';
$jscript11.=' legend: { ';
$jscript11.=' show: false, ';
$jscript11.=' responsive: true, ';
$jscript11.=' }, ';
$jscript11.=' tooltip: { ';
$jscript11.=' format: { ';
// $jscript11.=' // title: function (d) { return 'Data ' + d; }, ';
$jscript11.=' value: function (value, ratio, id) { ';
$jscript11.=' return formatNumber(value); ';
$jscript11.=' } ';
$jscript11.=' } ';
$jscript11.=' } ';
$jscript11.=' });';
}