javascript - Highcharts - "Style is null or not an object"

标签 javascript asp.net highcharts

所以,我在使用 Highcharts 时遇到了一些问题。它最近出现了一个只在 Internet Explorer 8 中触发的错误。失败的行来自 highcharts.src.js 文件的第 270 行:

function css (el, styles) {
  if (isIE) {
    if (styles && styles.opacity !== UNDEFINED) {
      styles.filter = 'alpha(opacity='+ (styles.opacity * 100) +')';
    }
  } 

  extend(el.style, styles); // This line fails...
}

创建图表的代码如下:

$(document).ready(function() {
  chartcontainer1700 = new Highcharts.Chart({
    chart: {
      renderTo: 'container1700'
    },
    title: {
      text: 'Loading chart...'
    }
  });
});

function onSuccess(options){
  if (options.hasOwnProperty('restErrorMessage') && options.restErrorMessage != null) {
     alert(options.restErrorMessage);
  }
  chartcontainer1700.destroy();
  chartcontainer1700 = new Highcharts.Chart(options);
  chartcontainer1700.redraw();
};

onSuccess 函数在 web 服务调用成功提供图表数据后被触发,该图表数据是一个 Json,如下所示:

{"chart": {
  "renderTo":"container0438",
  "zoomType":"xy"},
  "credits": { 
    "enabled": false,
    "position": {
      "align":"right",
      "x":-10,
      "verticalAlign":"bottom",
      "y":-5
  },
  "href":"http:\/\/www.website.com",
  "text":"Chart"
},
"legend": {
  "borderRadius":0,
  "borderWidth":0,
  "enabled":true
},
"series":[{"data":[67.5,67.75],"name":"ME","type":"spline","yAxis":0}],
"title":{"align":"center","text":""},
"xAxis":[{
  "categories":["Mar 22, 2011 - Mar 26, 2011","Mar 27, 2011 - Mar 29, 2011"],
  "maxPadding":5,"minPadding":1
 }],
 "yAxis":[{
   "labels":{
     "style":{"color":"Gray"}
   },
   "opposite":false,
   "title":{"text":"ME %","style":{"color":"Gray"}},
   "type":"spline"}],
   "exporting":{"enabled":true}
}

在其他浏览器中一切正常。有什么想法吗?

谢谢!

最佳答案

我搞砸了 highcharts,确实记得看到过这条错误消息,但我是在 chrome 上测试的。我发现对将要输入 highcharts 的 json 数据进行硬编码以确保它不是从服务返回的数据非常有帮助。我也会尝试不必调用 destroy 而只是想办法重绘图表。我知道建议销毁图表,但有时这对我来说是个问题。也许只是重复使用相同的图表实例 chartcontainer1700,并且只是更改传入的数据,然后重新绘制它。

关于javascript - Highcharts - "Style is null or not an object",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5475495/

相关文章:

javascript - 为什么 Array.prototype.forEach() 不能像 for 循环一样识别异步函数中的等待?

javascript - 使用 d3.xml 而不是 d3.json 绘制可折叠缩进树

javascript - 尝试使用 AJAX 将 JavaScript 变量传递给 PHP,但得到 'Undefined index'

c# - FileUpload.SaveAs 在删除 AD 后保存空的损坏文件

asp.net - Google Chrome在浏览器关闭后保留 session 变量

javascript - Highchart 在值工具提示后添加文本

highcharts - 如何在 Highcharts 的柱形图中显示值为零的列?

php - mySQL 与 PHP 到 JSON 用于客户端图表

javascript - 如何在指令模板中包含模板?

c# - 使 ASP.Net 页面过期