育知同创教育
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向TA提问 1) npm安装highcharts
2)定义变量
var Highcharts = require('highcharts');
3)获取元素
Highcharts.chart(this.$el, {...}) in "mounted" method because this.$el isn't available before "mounted"
4) 在调用beforeDestroy前销毁highcharts对象
举例如下:
<template>
<div><div>
</template>

<script>
var Highcharts = require('highcharts');
export default {
name : "Chart",
props : {
series : {
type: Array,
required: true
}
},
data : function() {
return {
target: undefined
}
},
mounted : function() {
this.target = Highcharts.chart(this.$el, {
title: {
text: 'Monthly Average Temperature',
x: -20 //center
},
subtitle: {
text: 'Source: WorldClimate.com',
x: -20
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
yAxis: {
title: {
text: 'Temperature (°C)'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
valueSuffix: '°C'
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'middle',
borderWidth: 0
},
series: this.series
});
},
beforeDestroy: function() {
this.target.destroy();
},
}
</script>