Google Charts with no data to display a blank chart - Javascript Google Chart

Javascript examples for Google Chart:Chart Configuration

Description

Google Charts with no data to display a blank chart

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <title>Line Chart Example</title> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
   </head> 
   <body> 
      <script type="text/javascript" src="https://www.google.com/jsapi?autoload={'modules':[{'name':'visualization','version':'1','packages':['corechart']}]}"></script> 
      <div id="chart_div" style="width: 900px; height: 500px;"></div> 
      <script type="text/javascript">
      google.setOnLoadCallback(drawChart);
      function drawChart() {/*  w  w  w  .jav  a 2  s. com*/
          var data = google.visualization.arrayToDataTable([
              [{
                  f: 'Date',
                  type: 'date'
              }, {
                  f: 'Line',
                  type: 'number'
              }], ]);
          var options = {
              title: 'Company Performance'
          };
          if (data.getNumberOfRows() == 0) {
              data.addRow([new Date(), 0])
              options.series = {
                  0: {
                      color: 'transparent'
                  }
              }
          }
          var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
          chart.draw(data, options);
      }

      </script>  
   </body>
</html>

Related Tutorials