我在本地声明了一个 highcart 函数:
function render(){
var Chart=null
Chart = new Highcharts.Chart({
chart: {
renderTo: container,
height: 400
},
title: {
text: 'Chart.update'
},
subtitle: {
text: 'Plain'
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
series: [{
type: 'column',
colorByPoint: true,
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4],
showInLegend: false
}]
});
}
假设我无法更改 render() 函数,我可以使用 Chart.update 工具来更改属性吗?
基本上我想重新创建功能 here ,但是对于 this example不改变功能。
这是否就像要求访问函数外部的局部变量一样,或者它仍然在全局某个地方定义?
最佳答案
您必须在 render
函数之前定义 var Chart=null
JS
var chart = null
function render() {
chart = new Highcharts.Chart({
chart: {
renderTo: container,
height: 400
},
title: {
text: 'Chart.update'
},
subtitle: {
text: 'Plain'
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
series: [{
type: 'column',
colorByPoint: true,
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4],
showInLegend: false
}]
});
}
render()
function plain() {
chart.update({
chart: {
inverted: false,
polar: false
},
subtitle: {
text: 'Plain'
}
});
}
function inverted() {
chart.update({
chart: {
inverted: true,
polar: false
},
subtitle: {
text: 'Inverted'
}
});
}
function polar() {
chart.update({
chart: {
inverted: false,
polar: true
},
subtitle: {
text: 'Polar'
}
});
}
HTML
<div id="container"></div>
<button id="plain" class="autocompare" onclick="plain()">Plain</button>
<button id="inverted" class="autocompare" onclick="inverted()">Inverted</button>
<button id="polar" class="autocompare" onclick="polar()">Polar</button>
关于javascript - 使用 renderTo 在图表上使用 Chart.update,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42848218/