vue引入echarts
首先是npm下载
npm install echarts --save
配置echarts.js,按需引入
// 引入 echarts 核心模块,核心模块提供了 echarts 使用必须要的接口。
import * as echarts from 'echarts/core';
// 引入柱状图图表,图表后缀都为 Chart
import { BarChart } from 'echarts/charts';
// 引入提示框,标题,直角坐标系,数据集,内置数据转换器组件,组件后缀都为 Component
import {
TitleComponent,
TooltipComponent,
GridComponent,
DatasetComponent,
TransformComponent
} from 'echarts/components';
// 标签自动布局,全局过渡动画等特性
import { LabelLayout, UniversalTransition } from 'echarts/features';
// 引入 Canvas 渲染器,注意引入 CanvasRenderer 或者 SVGRenderer 是必须的一步
import { CanvasRenderer } from 'echarts/renderers';
// 注册必须的组件
echarts.use([
TitleComponent,
TooltipComponent,
GridComponent,
DatasetComponent,
TransformComponent,
BarChart,
LabelLayout,
UniversalTransition,
CanvasRenderer
]);
export default echarts
vue页面使用
<template>
<div class="box boxall">
<h2>就业行业</h2>
<div class="contain blt">
<div id="main"></div>
</div>
<div class="boxfoot"></div>
</div>
</template>
<script>
import echarts from "@/utils/echarts";
export default {
mounted() {
this.initCharts(); //初始化渲染echart图标
},
methods: {
initCharts() {
// 获取数据
const option = {
grid: {
top: "15%",
left: "10%",
right: "8%",
bottom: "10%",
},
color: ["#2f89cf"],
tooltip: {
trigger: "axis",
axisPointer: {
type: "shadow",
},
},
xAxis: {
data: [ "旅游行业","教育培训", "游戏行业", "医疗行业", "电商行业", "社交行业", "金融行业" ],
axisLabel: {
color: "rgba(255,255,255,.8)",
fontSize: 12,
fontWeight: "bold",
},
axisLine: {
show: false,
},
},
yAxis: {
axisLabel: {
color: "rgba(255,255,255,.8)",
fontSize: 12,
fontWeight: "bold",
},
axisLine: {
show: true,
lineStyle: {
color: "rgba(255,255,255,.3)",
width: 2,
},
},
},
series: [
{
name: "比率",
type: "bar",
barWidth: "50%",
itemStyle: {
borderRadius: 5,
},
data: [200, 300, 300, 900, 1500, 1200, 600]
},
],
};
var myChart = echarts.init(document.getElementById("main")); //图标初始化
myChart.setOption(option); // 渲染页面
// 随着屏幕大小调节图标
window.addEventListener("resize", () => {
myChart.resize();
});
},
},
};
</script>
<style lang='less' scoped>
#main {
width: 100%;
height: 100%;
}
</style>

浙公网安备 33010602011771号