javascript - highcharts 无法读取属性 'legendBackgroundColor'

标签 javascript highcharts

我正在尝试使用 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/

相关文章:

javascript - 将当前 HTMLElement 传递给 ng-click

javascript - 检查动态选择的单选按钮

javascript - 在 chromium/puppeteer 中获取按列数拆分的 div 边界框

jquery - 如何在图表上绘图?

javascript - 错误类型错误 : Cannot read property '0' of undefined in angular-highcharts

javascript - 将 PHP 数组转换为 JS 数组(ISO 8859-1 字符)

javascript - jquery datepicker 根据两个日期之间的差异更改输入值

javascript - 如何在 Highcharts 中添加动态数据?

javascript - 根据可见系列更改饼图标题

javascript - 你如何在javascript中将纪元转换为可读的日期格式