Vue2.0 custom pie chart (Echarts) component method, vue2.0echarts

Source: Internet
Author: User

Vue2.0 custom pie chart (Echarts) component method, vue2.0echarts

1. Custom chart Components

Echarts. vue

<! -- Customize the echart component --> <template> <div> <! -- Echart table --> <div id = "myChart": style = "echartStyle"> </div> </template> <script> export default {props: {// style echartStyle: {type: Object, default () {return {}}}, // Title text titleText: {type: String, default :''}, // prompt box key name tooltipFormatter: {type: String, default: ''}, // sector region name opinion: {type: Array, default () {return []}, // The title of the prompt box seriesName: {type: String, default: ''}, // opinionData: {type: Array, default () {return [] }},}, data () {return {//}, mounted () {this. $ nextTick (function () {this. drawPie ('mychart')}, methods: {// listen to the slice chart and click eConsole (param) {// pass the value this to the parent component. $ emit ("currentEchartData", param. name) ;}, // draw the pie chart drawPie (id) {this. charts = this. $ echarts. init (document. getElementById (id); this. charts. on ("click", this. eConsole); this. charts. setOption ({title: {text: this. titleText, // Title text left: 'center'}, tooltip: {trigger: 'item', formatter: "{a} <br/>" + this. tooltipFormatter + ": {c}"}, legend: {bottom: 20, left: 'center', data: this. opinion // sector region name}, series: [{name: this. seriesName, // The title type: 'pie ', radius: '000000', center: ['000000', '000000'], selectedMode: 'Single', data: this. opinionData, // itemStyle: {emphasis: {shadowBlur: 10, shadowOffsetX: 0, shadowColor: 'rgba (0, 0, 0, 0.5) '}}}]}) }}</script> <style lang = "less" scoped ># myChart {width: 100% ;}</style>

2. Page call

Digoal. vue

<! -- Chart --> <template> <div> <! -- Title bar --> <mt-header title = "chart"> <router-link to = "/" slot = "left"> <mt-button icon = "back"> return </mt-button> </router-link> </mt-header> <! -- Content --> <m-echarts: echartStyle = "s": titleText = "a": tooltipFormatter = "B": opinion = "c": seriesName = "d ": opinionData = "e" v-on: currentEchartData = "getEchartData"> </m-echarts> </div> </template> <script> import mEcharts from '.. /components/Echarts 'export default {name: 'dirty', components: {mEcharts}, data () {return {a: 'fruit sale statistics', B: 'sales qty ', c: ['banana', 'apple ', 'Orange'], d: 'sales statistics', e: [{value: 3, name: 'banana '}, {value: 3, name: 'apple'}, {value: 3, name: 'orange'}], s: {height: ''}}, created () {// obtain the screen height this. s. height = document.doc umentElement. clientHeight-44 + 'px ';}, methods: {getEchartData (val) {console. log (val) ;}}</script> <style lang = "less" scoped >/// </style>

3,

The above vue2.0 custom pie chart (Echarts) component method is to share with you all the content, hope to give you a reference, but also hope you can support a lot of help home.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.