1. Installation Install npm install echarts --save 2. Introduction After the installation is complete, you can import all of import * as echarts from "echarts"; 3. UseAfter the introduction is completed, we can draw the corresponding chart through the interface provided by echarts. The usage is as follows: <template> <div class="echart" id="mychart" :style="{ float: 'left', width: '100%', height: '400px' }" ></div> </template> <script> import * as echarts from "echarts"; export default { data() { return { name: "Zhang Xue", xData: ["2020-02", "2020-03", "2020-04", "2020-05"], // horizontal coordinate data yData: [30, 132, 80, 134] // vertical coordinate data, corresponding to the horizontal coordinate}; }, mounted() { this.initEcharts(); }, methods: { initEcharts() { const option = { title: text: "ECharts Getting Started Example" }, tooltip: {}, legend: { data: ["sales volume"] }, xAxis: data: ["shirt", "sweater", "chiffon shirt", "pants", "high heels", "socks"] }, yAxis: {}, series: [ { name: "Sales Volume", type: "bar", // type is bar chart data: [5, 20, 36, 10, 10, 20] } ] }; const myChart = echarts.init(document.getElementById("mychart"));// Icon initialization myChart.setOption(option);// Rendering page// Adjust the chart with the screen size window.addEventListener("resize", () => { myChart.resize(); }); } } }; </script> The effect is as follows: 4. Introduce ECharts charts and components as needed The above code will import all charts and components in // Import the echarts core module, which provides the necessary interfaces for using echarts. import * as echarts from 'echarts/core'; // Import bar charts, all charts have the suffix "Chart" import { BarChart } from 'echarts/charts'; // Introduce prompt box, title, rectangular coordinate system, data set, built-in data converter components, all with the suffix Component import { TitleComponent, TooltipComponent, GridComponent, DatasetComponent, DatasetComponentOption, TransformComponent } from 'echarts/components'; // Label automatic layout, global transition animation and other features import { LabelLayout, UniversalTransition } from 'echarts/features'; // Import Canvas renderer. Note that importing CanvasRenderer or SVGRenderer is a necessary step. import { CanvasRenderer } from 'echarts/renderers'; // Register the required componentsecharts.use([ TitleComponent, TooltipComponent, GridComponent, DatasetComponent, TransformComponent, BarChart, LabelLayout, UniversalTransition, CanvasRenderer ]); // The following usage is the same as before, initialize the chart and set the configuration items var myChart = echarts.init(document.getElementById('main')); myChart.setOption({ // ... }); It should be noted that in order to ensure the smallest package size, This is the end of this article about introducing ECharts in Vue project. For more relevant content about introducing ECharts in Vue, please search previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Differences between proxy_pass in two modules in nginx
>>: Example code showing common graphic effects in CSS styles
Purpose: Treat Station A as the secondary directo...
Template 1: login.vue <template> <p clas...
1. What is an index? An index is a data structure...
Both methods can be used to execute a piece of ja...
html , address , blockquote , body , dd , div , d...
Table of contents 1. Shared CommonModule 2. Share...
Note: sg11 Our company only supports self-install...
Writing a Dockerfile Configure yum source cd /tmp...
1. Permanent modification, valid for all users # ...
RGBA is a CSS color that can set color value and ...
Table of contents Supports multiple types of filt...
definition Calcite can unify Sql by parsing Sql i...
Recently, the Vue project needs to refresh the da...
When the user's home directory becomes larger...
As an open source software, Apache is one of the ...