Home > Article > Web Front-end > How to use echarts in vue project
Instructions for use: 1. Use the "yarn add echarts" or "npm install echarts -S" or "cnpm install echarts -S" command to install Echarts; 2. Use "import echarts from ' in main.js echarts' Vue.prototype.$echarts = echarts" to introduce; 3. Just call the relevant api in the vue page.
The operating environment of this tutorial: windows7 system, vue3 version, DELL G3 computer.
Echarts is a commercial-grade data chart. It is a pure JavaScript icon library, compatible with most browsers. The bottom layer relies on the lightweight canvas class library ZRender to provide intuitive, vivid, interactive, and highly Personalized data visualization charts. Innovative drag-and-drop recalculation, data views, value range roaming and other features greatly enhance the user experience and empower users with the ability to mine and integrate data.
Echarts, it is a JS chart library that has nothing to do with the framework, but it is based on Js so that many frameworks can use it, such as Vue.
Choose one of the following installation methods
This project is installed using yarn
, echarts
The version number is 4.8.0
// yarn yarn add echarts // npm npm install echarts -S // cnpm cnpm install echarts -S
import echarts from 'echarts' Vue.prototype.$echarts = echartsReaching this step means you have finished the preparation work
<template> <div class="home"> </div> </template> <script> export default { name: 'Home', } </script>
as a container (there will be a small problem when using the id, which will be answered at the end)<pre class="brush:js;toolbar:false;"><div id="EChart" style="width: 300px; height: 300px;"></div></pre>
getRenderer() { console.log(this.$echarts); // 基于准备好的dom,初始化echarts实例 let EChart = this.$echarts.init(document.getElementById("EChart")); // 配置参数 let config = { title: { text: "悲伤日记" }, tooltip: {}, xAxis: { data: ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"], }, yAxis: {}, series: [ { name: "销量", type: "bar", data: [5, 20, 36, 10, 10, 20], }, ], }; // 设置参数 EChart.setOption(config); },
mounted() { // 在生命周期中调用 getRenderer 方法 this.getRenderer(); },
## People who eat melons: "What the hell Isn't it an official example? Can you show it off a little bit?"
address)
Remarks | ||
---|---|---|
https://echarts.apache.org/zh/option.html#title |
legend | |
https://echarts.apache.org/zh/option.html#legend |
xAxis | |
https://echarts.apache.org/zh/option.html#xAxis |
yAxis | |
https://echarts.apache.org/zh/option.html#yAxis |
series | |
https://echarts.apache.org/zh/option.html#series |
color | |
https://echarts.apache.org/zh/option.html#color |
The above is the detailed content of How to use echarts in vue project. For more information, please follow other related articles on the PHP Chinese website!