I have been working on projects related to big data recently, so let’s make a brief summary of the ECharts chart

Use ECharts diagrams in HTML

1. Import ECharts You can directly import the constructed ECharts file with labels

<! DOCTYPEhtml>
<html>
<head>
    <meta charset="utf-8">
    <! ECharts -->
    <script src="echarts.min.js"></script>
</head>
</html>
Copy the code

Before drawing, we need to prepare a DOM container with the height and width for ECharts.

<! -- Prepare a DOM with size (width and height) for ECharts
<div id="main" style="width: 600px; height:400px;"></div>
Copy the code

You can then initialize an echarts instance using the echarts.init method and generate a simple bar graph using the setOption method.

<script type="text/javascript">
   // Initializes the echarts instance based on the prepared DOM
   var myChart = echarts.init(document.getElementById('main'));
   // Specify the chart configuration items and data
   var option = {
       title: {
           text: 'Getting started with ECharts'
       },
       tooltip: {},
       legend: {
           data: ['sales']},xAxis: {
           data: ["Shirt"."Cardigan"."Chiffon shirt."."Pants"."High heels"."Socks"]},yAxis: {},
       series: [{
           name: 'sales'.type: 'bar'.data: [5.20.36.10.10.20]]}};// Display the chart using the configuration items and data you just specified.
   myChart.setOption(option);
</script>
Copy the code

And you have your first chart!

Use ECharts diagrams in VUE

1. Install echarts dependencies

npm install echarts -S
Copy the code

2, introduce echarts (1) global introduction

import echarts from 'echarts'
Vue.prototype.$echarts = echarts
Copy the code

(2) Introduction on demand

// Introduce the ECharts main module
var echarts = require('echarts/lib/echarts'); 
// Introduce bar chart
require('echarts/lib/chart/bar'); 
// Introduce line chart
require('echarts/lib/chart/line'); 
// Introduce pie chart
require('echarts/lib/chart/pie'); 
// Import components
require('echarts/lib/component/grid'); 
require('echarts/lib/component/tooltip'); 
require('echarts/lib/component/title');
require('echarts/lib/component/legend');
require('echarts/lib/component/legendScroll'); // (scroll legend)

Vue.prototype.$echarts = echarts
Copy the code

Create a div with width and height

<div id="main" :style="{width: '300px', height: '300px'}"></div>
Copy the code

(2) Initialize the echarts instance and draw the diagram

var myChart = this.$echarts.init(document.getElementById('main'));
myChart.setOption({ 
	title: { text: 'Getting started with ECharts' }, 
	tooltip: {}, 
	xAxis: { data: ['shirt'.'Cardigan'.'Chiffon shirt'.'pants'.'High heels'.'socks']},yAxis: {}, 
	series: [{ name: 'sales'.type: 'bar'.data: [5.20.36.10.10.20]}});Copy the code

I have also set up a vUE sample project to introduce Echarts charts on demand. At present, I only introduce simple bar charts, line charts and pie charts, and I will gradually add them later, Ollie!! Portal 🚀 🚀 🚀