vue 項目 引入 hightcharts

 

<template>

<div class='earlywarning'>

<div id="container"></div>

</div>

</template>

 

<script>

import * as Highcharts from 'highcharts'

export default {

data () {

return {}

},

mounted () {

this.drowCart()

},

methods: {

drowCart () {

const chart = Highcharts.chart(

'container', {

chart: {

spacing: [0, 0, 0, 0],

backgroundColor: '#073149'

},

title: {

floating: true,

text: '預警情況',

style: {

color: '#f8f8f8'

}

},

credits: {

enabled: false

},

tooltip: {

pointFormat: '{series.name}: <b>{point.y}個</b>'

},

plotOptions: {

pie: {

allowPointSelect: true,

cursor: 'pointer',

dataLabels: {

enabled: true,

format: '<b>{point.name}</b>: {point.y}個',

style: {

color:

(Highcharts.theme && Highcharts.theme.contrastTextColor) ||

'black'

}

},

point: {

events: {

mouseOver: function (e) {

chart.setTitle({

text: e.target.name + '\t' + e.target.y + '個'

})

}

}

}

}

},

series: [{

type: 'pie',

innerSize: '70%', // 環形的寬窄,數值越小環形越寬

name: '預警個數',

colors: ['#FFF30C', '#E6A23C', '#f56c6c'],

data: [

{ name: '黃色預警', y: 10 },

{ name: '橙色預警', y: 3 },

{ name: '紅色預警', y: 7 }

]

}]

}

// function (c) {

// // 圖表初始化完畢後的會掉函數

// // 環形圖圓心

// const centerY = c.series[0].center[1],

// titleHeight = parseInt(c.title.styles.fontSize);

// // 動態設置標題位置

// c.setTitle({

// y: centerY + titleHeight / 2

// })

// }

)

}

}

}

</script>

 

<style>

.earlywarning {

width: 100%;

height: 40%;

border: 1px solid red;

}

.highcharts-container {

width: 600px;

height: 400px;

border: 1px solid red;

margin: auto;

}

</style>

 

 小聲BB vue項目引入hightcharts 網上全是同一個答案太費勁了 記錄一下 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章