在旧对象上初始化新的highcharts对象

时间:2018-10-04 20:21:47

标签: javascript highcharts

在下面的javascript中调用chart.loadData时出现以下错误

  

TypeError:c.style未定义。 highcharts.src.js:18788:15


编辑:已解决(确定)

导致此特定错误的原因是由于尝试在上游完全不同的js文件中定义v.__prototype__.constructor(与HighCharts代码中的任何内容都没有命名冲突)。当然,这没有任何意义,但这是适合您的javascript


原始帖子的其他信息

我有Highcharts JS v6.1.4(2018-09-25),而addTitle函数中的那行(未缩小时)是if (!axisTitleOptions.style.width && !axis.isRadial)

我有以下js代码

var chart = {
    id: 'tr_chart',
    chart_obj: null,
    $elem: null,
    nodata: null,
    options: {},
    defaultOptions: function() {
        this.options = new Object({
            chart: { type: 'line'
        }, title: {
            text: 'Distance away'
        }, xAxis: {
            type: 'datetime', title: {
                text: "Date"
            },
            min: null, max: null
        }, yAxis: {
            title: {
                text: 'km'
            },
        }, series: [] })
    },
    startinit: function() {
        // set up chart
        this.defaultOptions();
        this.options.xAxis.min = parameters.startDate.valueOf(); //yes, these really do have values
        this.options.xAxis.max = parameters.endDate.valueOf();
    init: function(){
        this.startinit();
        this.chart_obj = Highcharts.chart(this.id, this.options);
        this.$elem = $(".tr_chart");
    },
    loadData: function(data){
        if (data.length < 1) {
            // this.restoreNoData();
            return;
        }
        this.startinit();
        console.log(this.options);
        // more code is here and ends with...
        this.chart_obj = Highcharts.chart(this.id, this.options);
    }
}

封装页面中存在以下HTML代码(除了jQuery等)

<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
...
<div id="tr_chart">
</div>

只有指示的单个对象(div或其他)具有该id值。

根据Firefox的检查器控制台,在记录行的loadData中,不知如何将我的this.options对象重新初始化为默认选项。而是用数据点填充该系列,并具有几个其他属性。具体来说,它具有chart.options.xAxis.indexchart.options.xAxis.isXchart.options.series[i]._colorIndexchart.options.series[i]._symbolIndex的值,表明选项对象仍然填充了元数据和来自先前对{{ 1}}“构造函数”。

数据截断的Highcharts.chart对象是(尝试重新初始化之后):

options

我在处理javascript对象时是否缺少某些东西?高图是否在第一次调用构造函数时就挂入“选项”对象,并且不允许我替换该对象?


我相信这可能已连接...在高图中我收到以下警告/非致命错误

{
  "chart": {
    "type": "line"
  },
  "title": {
    "text": "Distance away"
  },
  "xAxis": {
    "type": "datetime",
    "title": {
      "text": "Date"
    },
    "min": 1262332800000,
    "max": 1538681082811,
    "index": 0,
    "isX": true
  },
  "yAxis": {
    "title": {
      "text": "km"
    },
    "index": 0
  },
  "series": [
    {
      "name": "my first series name",
      "data": [
        [
          1422619771000,
          188.964
        ],
        [
          1422620874000,
          188.964
        ],
        [
          1423058407000,
          106.54
        ],
        [
          1423104758000,
          106.54
        ]
      ],
      "_colorIndex": 0,
      "_symbolIndex": 0
    },
    {
      "name": "and the second series name here",
      "data": [
        [
          1263477629000,
          325.329
        ],
        [
          1263477725000,
          325.329
        ],
        [
          1263519764000,
          287.487
        ],
        [
          1263519764000,
          287.487
        ] // ... and 100 more data points in this second series
     ],
      "_colorIndex": 1,
      "_symbolIndex": 1
    }
  ]
}

我还注意到有Error in parsing value for ‘text-anchor’. Declaration dropped. Unexpected value NaN parsing x attribute. highcharts.src.js:7324:18 Unexpected value undefined parsing rx attribute. highcharts.src.js:1119:14 Unexpected value undefined parsing ry attribute. highcharts.src.js:1119:14 Unexpected value NaN parsing x attribute. highcharts.src.js:5283:10 Unexpected value NaN parsing y attribute. highcharts.src.js:5283:10 Unexpected value NaN parsing width attribute. highcharts.src.js:5283:10 Unexpected value NaN parsing height attribute. highcharts.src.js:5283:10 Unexpected value NaN parsing width attribute. highcharts.src.js:5283:10 Unexpected value NaN parsing height attribute. elem.styles,但没有elem.element.style。其中elem.styleelem.element类型的对象,这里是该大概位置的堆栈跟踪。

text.highcharts-title

0 个答案:

没有答案