Let us take a look at the official website first: https://www.echartsjs.com/zh/index.html
Click For example, you can see various visual charts in the picture above. Select one of the charts:
After opening, the code is on the left and the chart on the right:
app.title = '环形图'; option = { tooltip: { trigger: 'item', formatter: "{a} <br/>{b}: {c} ({d}%)" }, legend: { orient: 'vertical', x: 'left', data:['直接访问','邮件营销','联盟广告','视频广告','搜索引擎'] }, series: [ { name:'访问来源', type:'pie', radius: ['50%', '70%'], avoidLabelOverlap: false, label: { normal: { show: false, position: 'center' }, emphasis: { show: true, textStyle: { fontSize: '30', fontWeight: 'bold' } } }, labelLine: { normal: { show: false } }, data:[ {value:335, name:'直接访问'}, {value:310, name:'邮件营销'}, {value:234, name:'联盟广告'}, {value:135, name:'视频广告'}, {value:1548, name:'搜索引擎'} ] } ] };
Then you only need a few steps to use it:
1. Local installation:
You can use npm to install ECharts:
npm install echarts
2. Introduce echarts into index.html
import echarts from 'echarts'
3. Write a div container to host the chart:
<div class="hccalone"> <div id="teamLeader" style="float:left;width:100%;height: 300px"></div> </div>
Set a div in the above code (set the height, size and other attributes, set An id)
4. Write a method to initialize the chart code (copy and paste the code from the official website document directly and modify the container id and the values of each part):
getTeamLeader(){ var myChart = echarts.init(document.getElementById('teamLeader')); myChart.setOption({ title : { text: '团队考核情况', x:'center' }, tooltip: { trigger: 'item', formatter: "{a} <br/>{b}: {c} ({d}%)" }, legend: { orient: 'vertical', x: 'left', data:['已完成','未完成'] }, series: [ { name:'访问来源', type:'pie', radius: ['50%', '70%'], avoidLabelOverlap: false, label: { normal: { show: false, position: 'center' }, emphasis: { show: true, textStyle: { fontSize: '30', fontWeight: 'bold' } } }, labelLine: { normal: { show: false } }, data:[ {value:50, name:'已完成'}, {value:50, name:'未完成'} ] } ] }); }
5. Finally, when initializing the page, just call this method and you can see the chart:
Other charts can be introduced into your own vue project using this method ~
PHP Chinese website has a large number of free JavaScript introductory tutorials, everyone is welcome to learn!
This article is reproduced from: https://www.jianshu.com/p/2894b781063b
The above is the detailed content of How to use visual charts echarts in Vue projects. For more information, please follow other related articles on the PHP Chinese website!