npm install echarts -S
在script中导入,比如:
import * as echarts from "echarts";
比如柱状图
<template>
<div id="total-orders-chart" style="width: 800px; height: 600px"></div>
</template>
<script>
import * as echarts from "echarts";
export default {
mounted() {
this.options()
},
methods: {
/**
* init方法
*/
options() {
const chart = echarts.init(document.getElementById("total-orders-chart"));
// 指定图表的配置项和数据
var option = {
xAxis: {
type: "category",
data: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"], //横坐标显示什么可以是返回来的数据可以进行数据过滤
},
yAxis: {
type: "value",
},
series: [
{
data: [820, 932, 901, 934, 1290, 1330, 1320], //纵坐标显示
type: "line",
smooth: true,
},
],
};
// 使用刚指定的配置项和数据显示图表。
chart.setOption(option);
},
},
};
</script>
显示成功