npm進行highchars的導入,導入完成后就可以進行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>// 導入chart組件import XChart from 'components/chart.vue'// 導入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)容了,希望能給大家一個參考,也希望大家多多支持武林網(wǎng)。
新聞熱點
疑難解答