【发布时间】:2016-07-12 18:59:51
【问题描述】:
我需要帮助编码我的 HTML 页面,以便当您从下拉菜单中选择“C152”选项时(参见下面的代码),Google 图表将更改为 C152 图表,而当您从下拉菜单,图表将变为 C172 图表。基本上,图表将根据下拉菜单中的选择而改变。 (每个图表都有一组不同的数据点和选项。)我已经做了一段时间的研究,但还没有找到我想要的东西来完成这项工作。我希望有人能指出我正确的方向。这是我的代码示例。提前致谢
<!DOCTYPE html>
<html>
<head>
<th>
<select name='select1' >
<option selected disabled>Choose</option>
<option onclick="c152()" value="c152">C152</option>
<option onclick="c172()" value="c172">C172</option>
</select></th>
<head>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load("current", {packages:["corechart"]});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var datac152 = google.visualization.arrayToDataTable
([['X', 'Y'],
[31, 1000],
[31, 1350],
[32.65, 1670],
[36.5, 1670],
[36.5, 1000]
]);
var datac172 = google.visualization.arrayToDataTable
([['X', 'Y'],
[35, 1500],
[35, 1950],
[38.65, 2300],
[47.3, 2300],
[47.3, 1500]
]);
var optionsc152 = {
legend: 'none',
hAxis: {title: 'Center of Gravity (inches)', minValue: 30, maxValue: 38 },
vAxis: {title: "Total Weight (lbs)"},
axes: {
y: {
all: {
range: {
max: 1800,
min: 1000
}
}
}
},
colors: ['#009933'],
pointSize: 0,
title: 'Cessna 152 Load Limits',
backgroundColor: '#eeeeee',
pointShape: 'circle'
};
var optionsc172 = {
legend: 'none',
hAxis: {title: 'Center of Gravity (inches)', minValue: 34, maxValue: 48 },
vAxis: {title: "Total Weight (lbs)"},
axes: {
y: {
all: {
range: {
max: 2300,
min: 1500
}
}
}
},
colors: ['#009933'],
pointSize: 0,
title: 'Cessna 172 Load Limits',
backgroundColor: '#eeeeee',
pointShape: 'circle'
};
var chart = new google.visualization.AreaChart(document.getElementById('chart_div'));
chart.draw(datac152, optionsc152);
}
</script>
</head>
<body>
<div id="chart_div" style="width: 963px; height: 500px;"></div>
</body>
</body>
</html>
【问题讨论】:
标签: javascript html drop-down-menu charts google-visualization