在Vue中使用highCharts繪制3d餅圖的方法
highcharts是國外知名基于javascript的圖表庫。由于中文官網(wǎng)的vue中使用highcharts配置繁瑣并且需要引入jquery作為依賴,所以棄用。
接下來,給各位伙伴簡要的講敘下highcharts在vue中的使用和配置方法。
首先使用 npm在你的項目中安裝vue-highcharts
npm install vue-highcharts --save
由于vue-highcharts依賴于highcharts,我們還需要安裝后者
npm install highcharts --save
安裝完成后,進入項目main.js進行配置:
import highcharts from 'highcharts' import VueHighCharts from 'vue-highcharts'
引入以上兩項之后,因為我們需要使用3d圖表,還需要引入:
import highcharts3d from 'highcharts/highcharts-3d'
調(diào)用3d圖表:
highcharts3d(highcharts)
OK,到此為止已經(jīng)在vue中配置好highcharts,接下來根據(jù)API繪制一份3d餅圖
新建一個餅圖的組件:
<template> <div class="container"> <div :id="id" :option="option"></div> </div> </template> <script> import HighCharts from 'highcharts' export default { props: { id: { type: String }, //option 是圖表的配置數(shù)據(jù) option: { type: Object } }, mounted() { HighCharts.chart(this.id, this.option) } } </script> <style scoped> /* 容器 */ .container { width: 1000px; height: 550px; } </style>
在需要使用餅圖的頁面里配置option數(shù)據(jù)
<template> <div class="charts"> <pie :id="id" :option="option"></pie> </div> </div> </template> <script> import pie from '../components/pie' import manes from '../components/list' export default { components: { pie, }, data() { return { id: 'test', option: { chart: { type: 'pie',//餅圖 options3d: { enabled: true,//使用3d功能 alpha: 60,//延y軸向內(nèi)的傾斜角度 beta: 0, } }, title: { text: '測試用'//圖表的標(biāo)題文字 }, subtitle: { text: ''//副標(biāo)題文字 }, plotOptions: { pie: { allowPointSelect: true,//每個扇塊能否選中 cursor: 'pointer',//鼠標(biāo)指針 depth: 35,//餅圖的厚度 dataLabels: { enabled: true,//是否顯示餅圖的線形tip } } }, series: [ { type: 'pie', name: '測試用1',//統(tǒng)一的前置詞,非必須 data: [ ['測試1',12],//模塊名和所占比,也可以{name: '測試1',y: 12} ['測試2',23], ['測試3',19], ['測試4',29] ] } ] } } }, } </script> <style scoped> </style>
看下效果。
更多的配置說明可以到中文官網(wǎng)查看 https://www.hcharts.cn/
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
解決vue-seamless-scroll滾動加點贊銜接處數(shù)據(jù)不同步問題
這篇文章主要介紹了解決vue-seamless-scroll滾動加點贊銜接處數(shù)據(jù)不同步問題,初步判斷可能是因為下方懸接vue-seamless-scroll是靜態(tài)的,沒同步DOM,本文給大家分享解決方法,感興趣的朋友一起看看吧2021-11-11vue自定義loader將行內(nèi)樣式px轉(zhuǎn)rem適配
這篇文章主要為大家介紹了vue自定義loader將行內(nèi)樣式px轉(zhuǎn)rem適配示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-08-08Vue中的 mixins 和 provide/inject詳解
這篇文章主要介紹了Vue中的 mixins 和 provide/inject詳解,本文結(jié)合實例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-07-07reactive readonly嵌套對象轉(zhuǎn)換功能實現(xiàn)詳解
這篇文章主要為大家介紹了reactive readonly嵌套對象轉(zhuǎn)換功能實現(xiàn)詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-12-12微信小程序?qū)崙?zhàn)基于vue2實現(xiàn)瀑布流的代碼實例
瀑布流,又稱瀑布流式布局,是比較流行的一種網(wǎng)站頁面布局,視覺表現(xiàn)為參差不齊的多欄布局,隨著頁面滾動條向下滾動,這種布局還會不斷加載數(shù)據(jù)塊并附加至當(dāng)前尾部,這篇文章主要介紹了微信小程序?qū)崙?zhàn),基于vue2實現(xiàn)瀑布流,需要的朋友可以參考下2022-12-12