no-op if 语句导致 google 图表失败?

no-op if statement causes google charts to fail?

javascript if 语句怎么会导致这种情况? if 语句的主体总是被执行,但是 if 语句的存在似乎导致 google 图表无法正常工作...

google.load('visualization', '1', {packages: ['corechart']});
...
...
...

var chart1 = new google.visualization.PieChart(document.getElementById('chartId1'));
var chart2 = new google.visualization.PieChart(document.getElementById('chartId2'));
...

var drawCharts = function() {
  var chart1Width = jQuery('#chartId1').width();
  var chart2Width = jQuery('#chartId2').width();
  ...

  var data = new google.visualization.DataTable();
  var chartOptions = {...};

  data.addColumn(...);
  data.addColumn(...);
  data.addRows([...]);
  chart1.draw(data,chartOptions);
  console.log('chart 1 drawn');

  //if I uncomment the next line the chart is not drawn
  //if (chart2Width > 80) {
  data = new google.visualization.DataTable();
  data.addColumn(...);
  data.addColumn(...);
  data.addRows([...]);
  chart2.draw(data,chartOptions);
  console.log('chart 2 drawn');
  //if I uncomment the next line the chart is not drawn
  //} else {console.log('chart 2 not drawn');}
};
drawCharts();
jQuery(...).bind(...., function() {drawCharts();});

此外,只有在添加 if 语句时,我才会从 chart2.draw(...); 行得到大量异常:Error: Invalid value for <circle> attribute cy="NaN"Error: Invalid value for <path> attribute d="MNaN,NaNL226,NaNL226,1.5L409.5,1.5"Error: Invalid value for <path> attribute d="MNaN,NaNL206,NaNL206,1.5L22.5,1.5" 等...

因为 console.log('chart 2 drawn'); 在任何一种情况下都会发生,这意味着 if 语句应该没有效果......但是图表不显示并且我得到异常......

javascript if 语句怎么会导致这种情况?

我通过在尝试绘制之前强制图形容器的高度解决了这个问题...

if (chart2Width > 80) {
  jQuery('#chartId2').height(chart2Width/2);
  data = new google.visualization.DataTable();
  data.addColumn(...);
  data.addColumn(...);
  data.addRows([...]);
  chart2.draw(data,chartOptions);
  console.log('chart 2 drawn');
} else {
  console.log('chart 2 not drawn');
}

显然 chartArea.height 配置选项没有按预期工作...

仍然不知道为什么在不可见的情况下渲染图形会导致可忽略的错误,但是如果未明确设置高度,则需要这些错误才能使其在可见时工作...