[ { "column1": "co_short_name", "column2": "装机容量", "column3": "机组类型;风电、光伏、分布式" }, { "column1": "崇明燃气", "column2": "8480.0", "column3": "燃气" }, { "column1": "奉贤", "column2": "9260.0", "column3": "燃气" }, { "column1": "淮北", "column2": "13500.0", "column3": "煤电" }, { "column1": "临港", "column2": "16520.0", "column3": "燃气" }, { "column1": "申皖", "column2": "13200.0", "column3": "煤电" }, { "column1": "外二", "column2": "18000.0", "column3": "煤电" }, { "column1": "外三", "column2": "20000.0", "column3": "煤电" }, { "column1": "吴二", "column2": "12000.0", "column3": "煤电" }, { "column1": "吴忠", "column2": "7000.0", "column3": "煤电" } ]处理数据,通过echarts绘制一个多列柱状图,煤电和燃煤作为图例
时间: 2023-07-06 11:40:10 浏览: 68
非常抱歉,刚才我的回答有误,燃煤应该是指煤电,我理解错误了。以下是正确的回答:
您可以先对数据进行处理,提取出煤电和燃气的装机容量:
```python
coal_power = []
gas_power = []
for data in data_list[1:]:
if data['column3'] == '煤电':
coal_power.append(float(data['column2']))
elif data['column3'] == '燃气':
gas_power.append(float(data['column2']))
```
接下来使用 echarts 绘制多列柱状图:
```javascript
// 基于准备好的dom,初始化echarts实例
var myChart = echarts.init(document.getElementById('main'));
// 指定图表的配置项和数据
var option = {
legend: {
data: ['煤电', '燃气']
},
xAxis: {
type: 'category',
data: ['崇明燃气', '奉贤', '淮北', '临港', '申皖', '外二', '外三', '吴二', '吴忠']
},
yAxis: {
type: 'value'
},
series: [
{
name: '煤电',
type: 'bar',
data: coal_power
},
{
name: '燃气',
type: 'bar',
data: gas_power
}
]
};
// 使用刚指定的配置项和数据显示图表。
myChart.setOption(option);
```
这样就可以绘制出一个多列柱状图,其中煤电和燃气为图例,x 轴为电站名称,y 轴为装机容量。
阅读全文