简体   繁体   中英

How to show a empty google pie chart when there no data?

I want to create a chart even if the chart have no data. But it shows no data available. Here is the code which I am using:

 <script type="text/javascript">
         google.charts.load('current',  {packages: ["corechart","calendar","table"]});      
        google.charts.setOnLoadCallback(drawChart);


          function drawChart()
          {
               var data = new google.visualization.DataTable();
               data.addColumn('string', 'Nama Barang');
               data.addColumn('number', 'Jumlah Transaksi');

                        data.addRows
                        ([
                              <?php
                              $coba = "";
                              $petik = "'";
                                  foreach ($dataPie_k as $row)
                                  {

                                    $coba = $coba."['$row->nama', $row->total],";
                                  }

                                      echo substr($coba,0,strlen($coba)-1);

                              ?>    
                        ]);



            var options = 
            {
              title: 'Rating 5', 
              is3D: true,
              legend: 'none',

              pieSliceText: 'label',

            };

            var chart = new google.visualization.PieChart(document.getElementById('piechart'));

            chart.draw(data, options);

            }
    </script>

Is it possible to display a chart if there is no data? Any help would be much appreciated. please help me.

Set sliceVisibilityThreshold:0 in options as

var options = 
      {
        title: 'Rating 5', 
        is3D: true,
        legend: 'none',

        pieSliceText: 'label',
        sliceVisibilityThreshold:0

      };

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM