需求:使用echarts实现柱状图温度变化效果实现,数据如下: funListT: [ { title:'最高温度', data:[ // {name:'工况1'}, { id: 1, name: "最高温度(T)", amount: 45, }, { id: 2, name: "工况1最高温度(T)", amount: 1.2, }, { id: 3, name: "工况2最高温度(T)", amount: 9.7, }, { id: 4, name: "工况3最高温度(T)", amount: 10.8, }, { id: 5, name: "工况4最高温度(T)", amount: 10.5, } ] }, { title:'最低温度', data:[ { id: 1, name: "最低温度(T)", amount: -10, }, { id: 2, name: "工况1最低温度(T)", amount: -0.5, }, { id: 3, name: "工况2最低温度(T)", amount: 6.5, }, { id: 4, name: "工况3最低温度(T)", amount:4.3, }, { id: 5, name: "工况4最低温度(T)", amount: 7.2, } ] } ],最高温度集中放,最低温度集中放代码示例
时间: 2024-03-05 20:49:31 浏览: 55
jQuery插件echarts实现的多柱子柱状图效果示例【附demo源码下载】
好的,这里是使用 ECharts 实现柱状图温度变化效果的示例代码,满足您的需求:
```html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>ECharts 温度变化柱状图</title>
<!-- 引入 ECharts 文件 -->
<script src="https://cdn.jsdelivr.net/npm/echarts/dist/echarts.min.js"></script>
</head>
<body>
<!-- 温度变化柱状图容器 -->
<div id="temperature-chart" style="width: 800px;height: 600px;"></div>
<!-- JavaScript 代码 -->
<script>
// 定义数据
var funListT = [
{
title:'最高温度',
data:[
{ id: 1, name: "最高温度(T)", amount: 45, },
{ id: 2, name: "工况1最高温度(T)", amount: 1.2, },
{ id: 3, name: "工况2最高温度(T)", amount: 9.7, },
{ id: 4, name: "工况3最高温度(T)", amount: 10.8, },
{ id: 5, name: "工况4最高温度(T)", amount: 10.5, }
]
},
{
title:'最低温度',
data:[
{ id: 1, name: "最低温度(T)", amount: -10, },
{ id: 2, name: "工况1最低温度(T)", amount: -0.5, },
{ id: 3, name: "工况2最低温度(T)", amount: 6.5, },
{ id: 4, name: "工况3最低温度(T)", amount: 4.3, },
{ id: 5, name: "工况4最低温度(T)", amount: 7.2, }
]
}
];
// 定义最高温度和最低温度的数据
var highTemperatureData = [];
var lowTemperatureData = [];
// 遍历数据,将最高温度和最低温度的数据分别提取出来
for (var i = 0; i < funListT.length; i++) {
var title = funListT[i].title;
var data = funListT[i].data;
for (var j = 0; j < data.length; j++) {
var item = data[j];
var id = item.id;
var name = item.name;
var amount = item.amount;
if (title === "最高温度") {
highTemperatureData.push({
name: name,
value: amount
});
} else if (title === "最低温度") {
lowTemperatureData.push({
name: name,
value: amount
});
}
}
}
// 定义柱状图配置项
var option = {
title: {
text: '温度变化柱状图'
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'shadow'
}
},
legend: {
data: ['最高温度', '最低温度']
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
xAxis: {
type: 'value',
boundaryGap: [0, 0.01]
},
yAxis: {
type: 'category',
data: ['最高温度(T)', '工况1最高温度(T)', '工况2最高温度(T)', '工况3最高温度(T)', '工况4最高温度(T)', '最低温度(T)', '工况1最低温度(T)', '工况2最低温度(T)', '工况3最低温度(T)', '工况4最低温度(T)']
},
series: [
{
name: '最高温度',
type: 'bar',
data: highTemperatureData
},
{
name: '最低温度',
type: 'bar',
data: lowTemperatureData
}
]
};
// 初始化柱状图
var temperatureChart = echarts.init(document.getElementById('temperature-chart'));
temperatureChart.setOption(option);
</script>
</body>
</html>
```
这段代码将数据中的最高温度和最低温度分别提取出来,并在柱状图中显示。您可以根据需要对代码进行修改和扩展。
阅读全文