用echarts写一个图标和表格和表单一起的demo
时间: 2024-06-11 07:06:46 浏览: 133
抱歉,我是一名语言模型,无法提供您所需的视觉化代码。但我可以为您提供一个基本的Echarts图表示例,您可以根据您的需求进行修改和扩展。
HTML代码:
```html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Echarts Demo</title>
<script src="https://cdn.jsdelivr.net/npm/echarts@5.2.1/dist/echarts.min.js"></script>
</head>
<body>
<div id="chart" style="width: 800px; height: 400px;"></div>
<table id="table">
<thead>
<tr>
<th>Year</th>
<th>Population</th>
<th>GDP</th>
</tr>
</thead>
<tbody>
<tr>
<td>2010</td>
<td>133.97</td>
<td>603.58</td>
</tr>
<tr>
<td>2011</td>
<td>136.07</td>
<td>749.24</td>
</tr>
<tr>
<td>2012</td>
<td>137.87</td>
<td>846.73</td>
</tr>
<tr>
<td>2013</td>
<td>139.01</td>
<td>963.67</td>
</tr>
<tr>
<td>2014</td>
<td>140.28</td>
<td>1046.33</td>
</tr>
<tr>
<td>2015</td>
<td>141.71</td>
<td>1123.58</td>
</tr>
<tr>
<td>2016</td>
<td>143.17</td>
<td>1224.91</td>
</tr>
<tr>
<td>2017</td>
<td>144.67</td>
<td>1367.82</td>
</tr>
<tr>
<td>2018</td>
<td>146.27</td>
<td>1486.57</td>
</tr>
<tr>
<td>2019</td>
<td>147.87</td>
<td>1545.68</td>
</tr>
<tr>
<td>2020</td>
<td>149.58</td>
<td>1605.14</td>
</tr>
</tbody>
</table>
<form>
<label for="year">Year:</label>
<select id="year" name="year">
<option value="2010">2010</option>
<option value="2011">2011</option>
<option value="2012">2012</option>
<option value="2013">2013</option>
<option value="2014">2014</option>
<option value="2015">2015</option>
<option value="2016">2016</option>
<option value="2017">2017</option>
<option value="2018">2018</option>
<option value="2019">2019</option>
<option value="2020">2020</option>
</select>
<input type="submit" value="Submit">
</form>
<script>
var chart = echarts.init(document.getElementById('chart'));
var option = {
title: {
text: 'Population and GDP of China (2010-2020)'
},
tooltip: {
trigger: 'axis'
},
legend: {
data: ['Population', 'GDP']
},
xAxis: {
type: 'category',
data: ['2010', '2011', '2012', '2013', '2014', '2015', '2016', '2017', '2018', '2019', '2020']
},
yAxis: [{
type: 'value',
name: 'Population (million)'
}, {
type: 'value',
name: 'GDP (billion USD)'
}],
series: [{
name: 'Population',
type: 'bar',
data: [133.97, 136.07, 137.87, 139.01, 140.28, 141.71, 143.17, 144.67, 146.27, 147.87, 149.58]
}, {
name: 'GDP',
type: 'line',
yAxisIndex: 1,
data: [603.58, 749.24, 846.73, 963.67, 1046.33, 1123.58, 1224.91, 1367.82, 1486.57, 1545.68, 1605.14]
}]
};
chart.setOption(option);
var table = document.getElementById('table');
var form = document.querySelector('form');
form.addEventListener('submit', function(event) {
event.preventDefault();
var year = form.year.value;
for (var i = 1; i < table.rows.length; i++) {
var row = table.rows[i];
if (row.cells[0].textContent !== year) {
row.style.display = 'none';
} else {
row.style.display = '';
}
}
});
</script>
</body>
</html>
```
这个示例包括了一个柱状图和一张表格,还有一个下拉菜单表单。您可以根据您的需求进行修改和扩展。
阅读全文