设置echarts 折线图为12项数据
时间: 2024-09-28 16:13:22 浏览: 38
在ECharts中创建一个包含12项数据的折线图,首先你需要确保有恰当的数据结构,并使用ECharts的API来设置。以下是一个简单的例子:
```javascript
// 引入ECharts库
import echarts from 'echarts';
// 假设你有如下12项数据
const data = [
{ year: '2020', value: 10 },
{ year: '2021', value: 15 },
{ year: '2022', value: 20 },
// ... (直到第12项)
];
// 创建一个图表实例
const chart = echarts.init(document.getElementById('main'));
// 绘制折线图配置项
const option = {
title: {
text: '年度销售额折线图'
},
xAxis: {
type: 'category',
data: data.map(item => item.year) // x轴数据为年份列表
},
yAxis: {
type: 'value'
},
series: [{
name: '销售额',
type: 'line', // 使用折线图
data: data.map(item => item.value) // y轴数据为数值列表
}]
};
// 渲染图表
chart.setOption(option);
```
在这个例子中,`xAxis`和`series`分别对应了折线图的X轴和Y轴数据,通过`.map()`遍历数据数组来获取每个元素对应的值。
阅读全文
相关推荐

















