我正在尝试使用 highcharts 创建一个图表来表示一些数据。但是,我在包含文件时收到以下错误。我有最新版本的 Highcharts。 是否是导入主题文件时出现问题,如果是,我该如何解决? /image/b5OIn.png
Jade 模板引擎,包括 JavaScript 代码:
script(type="text/javascript", src="javascripts/jquery.min.js")
script(type="text/javascript", src="javascripts/highcharts.js")
script(type="text/javascript", src="javascripts/client-project.js")
Chrome 控制台错误:
Uncaught TypeError: Cannot read property 'legendBackgroundColor' of undefined
(anonymous function)client-project.js:64
f.extend._Deferred.e.resolveWithjquery.min.js:1
e.extend.readyjquery.min.js:1
c.addEventListener.B
JavaScript 直接取自 highcharts 演示(未更改)“client-project.js”:
var chart;
$(document).ready(function() {
chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
zoomType: 'xy'
},
title: {
text: 'Average Monthly Temperature and Rainfall in Tokyo'
},
subtitle: {
text: 'Source: WorldClimate.com'
},
xAxis: [{
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
}],
yAxis: [{ // Primary yAxis
labels: {
formatter: function() {
return this.value +'°C';
},
style: {
color: '#89A54E'
}
},
title: {
text: 'Temperature',
style: {
color: '#89A54E'
}
}
}, { // Secondary yAxis
title: {
text: 'Rainfall',
style: {
color: '#4572A7'
}
},
labels: {
formatter: function() {
return this.value +' mm';
},
style: {
color: '#4572A7'
}
},
opposite: true
}],
tooltip: {
formatter: function() {
return ''+
this.x +': '+ this.y +
(this.series.name == 'Rainfall' ? ' mm' : '°C');
}
},
legend: {
layout: 'vertical',
align: 'left',
x: 120,
verticalAlign: 'top',
y: 100,
floating: true,
backgroundColor: Highcharts.theme.legendBackgroundColor || '#FFFFFF'
},
series: [{
name: 'Rainfall',
color: '#4572A7',
type: 'column',
yAxis: 1,
data: [49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
}, {
name: 'Temperature',
color: '#89A54E',
type: 'spline',
data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]
}]
});
});
最佳答案
主题文件与 highcharts.js 是分开的,因此您还需要包含其中一个。它们位于发行版的此文件夹中:
Highcharts-2.1.9\js\themes
请参阅 installation instructions 的第四步
关于javascript - highcharts 无法读取属性 'legendBackgroundColor',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8436435/