在vue項目中引入highcharts圖表的方法(詳解)
npm進行highchars的導(dǎo)入,導(dǎo)入完成后就可以進行highchars的可視化組件開發(fā)了
npm install highcharts --save
1、components目錄下新建一個chart.vue組件
<template> <div class="x-bar"> <div :id="id" :option="option"></div> </div> </template> <script> import HighCharts from 'highcharts' export default { // 驗證類型 props: { id: { type: String }, option: { type: Object } }, mounted() { HighCharts.chart(this.id,this.option) } } </script>
2、chart組件建好后,開始創(chuàng)建chart-options目錄,里面創(chuàng)建一個options.js用來存放模擬的chart數(shù)據(jù),如下圖目錄
如下圖我寫的一個柱狀圖的數(shù)據(jù)
module.exports = { bar: { chart: { type:'column'//指定圖表的類型,默認是折線圖(line) }, credits: { enabled:false },//去掉地址 title: { text: '我的第一個圖表' //指定圖表標題 }, colors: ['#058DC7', '#50B432', '#ED561B', '#DDDF00', '#24CBE5' ], xAxis: { categories: ['1號', '2號', '3號','3號','3號'] //指定x軸分組 }, yAxis: { title: { text: '最近七天', //指定y軸的標題 }, }, plotOptions: { column: { colorByPoint:true }, }, series: [{ //指定數(shù)據(jù)列 name: '小明', data: [{ y:1000, color:"red"}, 5000, 4000,5000,2000] //數(shù)據(jù) }] } }
3、引用chart組件
<template> <div id="app"> <x-chart :id="id" :option="option"></x-chart> </div> </template> <script> // 導(dǎo)入chart組件 import XChart from 'components/chart.vue' // 導(dǎo)入chart組件模擬數(shù)據(jù) import options from './chart-options/options' export default { name: 'app', data() { let option = options.bar return { id: 'test', option: option } }, components: { XChart } } </script> <style> #test { width: 400px; height: 400px; margin: 40px auto; } </style>
效果如下圖所示
以上這篇在vue項目中引入highcharts圖表的方法(詳解)就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
如何使用Vue3.2+Vite2.7從0快速打造一個UI組件庫
構(gòu)建工具使用vue3推薦的vite,下面這篇文章主要給大家介紹了關(guān)于如何使用Vue3.2+Vite2.7從0快速打造一個UI組件庫的相關(guān)資料,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下2022-09-09vue使用Google Recaptcha驗證的實現(xiàn)示例
我們最近的項目中需要使用谷歌機器人驗證,所以就動手實現(xiàn)一下,本文就來詳細的介紹一下vue Google Recaptcha驗證,感興趣的可以了解一下2021-08-08vue3使用vuedraggable實現(xiàn)拖拽功能
這篇文章主要為大家詳細介紹了vue3使用vuedraggable實現(xiàn)拖拽功能,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-04-04