javascript - vue数据更改后Highcharts图表未重绘
问题描述
我从以下网址获取示例:https ://www.highcharts.com/demo/column-stacked
还参考了一些代码:如何在 Highcharts 中使用 Vue 绑定数据?
我建立一个样本如下:
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.13/vue.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highcharts/7.1.1/highcharts.js"></script>
</head>
<body>
<div id="app">
<div id="container">
</div>
</div>
</body>
</html>
<script>
new Vue({
el: "#app",
data: {
chart: undefined,
config: {
chart: {
type: 'column'
},
title: {
text: 'Stacked column chart'
},
xAxis: {
categories: ['Apples', 'Oranges', 'Pears', 'Grapes', 'Bananas']
},
yAxis: {
min: 0,
title: {
text: 'Total fruit consumption'
},
stackLabels: {
enabled: true,
style: {
fontWeight: 'bold',
color: ( // theme
Highcharts.defaultOptions.title.style &&
Highcharts.defaultOptions.title.style.color
) || 'gray'
}
}
},
legend: {
align: 'right',
x: -30,
verticalAlign: 'top',
y: 25,
floating: true,
backgroundColor:
Highcharts.defaultOptions.legend.backgroundColor || 'white',
borderColor: '#CCC',
borderWidth: 1,
shadow: false
},
tooltip: {
headerFormat: '<b>{point.x}</b><br/>',
pointFormat: '{series.name}: {point.y}<br/>Total: {point.stackTotal}'
},
plotOptions: {
column: {
stacking: 'normal',
dataLabels: {
enabled: true
}
}
},
series: [{
name: 'John',
data: [3, 3, 4, 8, 2]
}, {
name: 'Jane',
data: [3, 2, 3, 2, 1]
}, {
name: 'Joe',
data: [3, 4, 4, 3, 5]
}]
},
},
mounted() {
this.render();
// simulation of some data changing after some time
setTimeout(() => {
this.config.series = [{
name: 'John',
data: [53, 23, 24, 27, 32]
}, {
name: 'Jane',
data: [23, 22, 23, 32, 31]
}, {
name: 'Joe',
data: [33, 24, 24, 32, 35]
}]
console.log('updated')
}, 3000)
},
watch: {
config() {
this.render();
},
},
methods: {
render() {
this.chart = Highcharts.chart('container', this.config)
}
}
})
</script>
但我不知道为什么在 config.series 更新后图表不会重绘(每个类别的值更高)。
解决方案
推荐阅读
- php - Prestashop 1.6 -> 通过 ajax 更改订单状态,电子邮件错误
- c++ - Qt:未找到 QTableWidget::cellClicked 信号/插槽的问题
- java - jshell(Java 9 shell)集成在 SublimeREPL 中没有响应
- python - 如何在 Python 中使用 BeautifulSoup 在 XML 文件中获取所有具有相同名称的标签?
- chromium-embedded - c# Cefsharp (like chromium) 不在 facebook 上显示视频
- jquery - 标题仅显示几秒钟
- bash - 检查函数返回是否在区间内
- intellij-idea - Run single Kotlin file
- python-3.x - 如何根据另一个数据框中的列值创建布尔列
- reactjs - 显示不同的错误 react redux