我在本地声明了一个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却不会改变功能。
这就像要求访问函数外部的局部变量,还是仍然在全局某处定义?
答案 0 :(得分:1)
您必须在var chart=null
函数
render
的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>