在Vue中使用highCharts绘制3d饼图

highcharts是国外知名基于javascript的图表库。因为中文官网的vue中使用highcharts配置繁琐而且须要引入jquery做为依赖,因此弃用。
接下来,给各位伙伴简要的讲叙下highcharts在vue中的使用和配置方法。javascript

首先使用 npm在你的项目中安装vue-highcharts

npm install vue-highcharts --save

因为vue-highcharts依赖于highcharts,咱们还须要安装后者

npm install highcharts --save

安装完成后,进入项目main.js进行配置:vue

import highcharts from 'highcharts'
import VueHighCharts from 'vue-highcharts'

引入以上两项以后,由于咱们须要使用3d图表,还须要引入:

import highcharts3d from 'highcharts/highcharts-3d'

调用3d图表:

highcharts3d(highcharts)

OK,到此为止已经在vue中配置好highcharts,接下来根据API绘制一份3d饼图
新建一个饼图的组件:java

<template>
<div class="container">
    <div :id="id" :option="option"></div>
</div>
</template>
<script>
import HighCharts from 'highcharts'
export default {
    props: {
        id: {
            type: String
        },
            //option 是图表的配置数据
        option: {
            type: Object
        }
    },
    mounted() {
        HighCharts.chart(this.id, this.option)
    }
}
</script>

<style scoped>
/* 容器 */    
.container {
width: 1000px;
height: 550px;
}
</style>

在须要使用饼图的页面里配置option数据jquery

<template>
    <div class="charts">
        <pie :id="id" :option="option"></pie>
    </div>
</template>

<script>
import Bing from '../components/Bing'
export default {
    components: {
        pie,
    },
    data() {
        return {
            id: 'test',
            option: {
                chart: {
                    type: 'pie',//饼图
                     options3d: {
                         enabled: true,//使用3d功能
                         alpha: 60,//延y轴向内的倾斜角度
                         beta: 0,   
                     }
                },
                title: {
                    text: '测试用'//图表的标题文字
                },
                subtitle: {
                    text: ''//副标题文字
                },

            plotOptions: {
                pie: {
                    allowPointSelect: true,//每一个扇块可否选中
                    cursor: 'pointer',//鼠标指针
                    depth: 35,//饼图的厚度
                    dataLabels: {
                        enabled: true,//是否显示饼图的线形tip
                    }
                }
            },
                series: [
                {
                    type: 'pie',
                    name: '测试用1',//统一的前置词,非必须
                    data: [
                        ['测试1',12],//模块名和所占比,也能够{name: '测试1',y: 12}
                        ['测试2',23],
                        ['测试3',19],
                        ['测试4',29]
                    ]
                 }
                ]
            }
        }
    },

}
</script>

<style scoped>

</style>

看下效果。git

clipboard.png

更多的配置说明能够到中文官网查看 https://www.hcharts.cn/
欢迎讨论,须要git demo的能够留言,see you。npm