我试图弄清楚如何在 js 数组中添加 if 语句,我在想也许速记条件会起作用,但我没有运气,这就是我所拥有的。
如果值不为空,我试图只包含数组。
gross1 = document.getElementById('gross1').value;
profit1 = document.getElementById('profit1').value;
gross2 = document.getElementById('gross2').value;
profit2 = document.getElementById('profit2').value;
gross3 = document.getElementById('gross3').value;
profit3 = document.getElementById('profit3').value;
function drawVisualization() {
var wrapper = new google.visualization.ChartWrapper({
chartType: 'ColumnChart',
dataTable: [['', 'Sales', 'Cost of Goods'],
['Product 1', parseInt(gross1), parseInt(profit1)],
if(gross2 != '' && profit2 != ''){
['Product 2', parseInt(gross2), parseInt(profit2)],
}elseif(gross3 != '' && profit != ''){
['Product 3', parseInt(gross3), parseInt(profit3)]
}],