highcharts无法读取属性'legendBackgroundColor'

highcharts Cannot read property 'legendBackgroundColor'

本文关键字:legendBackgroundColor 属性 读取 highcharts      更新时间:2023-09-26

我试图创建一个图表使用highcharts来表示一些数据。但是,我在包括文件时得到以下错误。我有Highcharts的最新版本。这可能是导入主题文件的问题,如果是这样,我该如何解决?https://i.stack.imgur.com/b5OIn.png

翡翠模板引擎,包括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

参见安装说明的第四步

相关文章:
  • 没有找到相关文章