<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script src="https://cdn.jsdelivr.net/npm/echarts@5.4.2/dist/echarts.min.js"></script>
<div id="main" style="width: 600px;height:500px;"></div>
<script>
var myChart = echarts.init(document.getElementById('main'));//初始化容器
var option = {
title: {
text: '某日部分地区(单位:摄氏度)'
},
dataset: {
source: [
['城市', '温度'],
['北京', 9],
['上海', 15],
['广州', 24],
['深圳', 25],
['哈尔滨', 7],
['武汉', 13]
]
},
xAxis: {
name: '城市',
type: 'category'
},
yAxis: {
name: '温度',
},
series: [
{
type: 'line',
smooth: true,
//修改为true就为将折线曲线,该为0为曲线
label: {
show: true,
position: 'top'
},
encode: {
// 将"城市"映射到X轴
x: '城市',
// 将"温度"映射到Y轴
y: '温度'
}
}
]
};
// 应用配置项
myChart.setOption(option);
</script>
</body>
</html>