首页 > 解决方案 > Chart.options 返回“'chart' 类型上不存在属性 'options'”

问题描述

创建图表后,我需要能够编辑图表的选项。为此,我正在运行 chart.options.[...] 但这会引发错误“'Chart' 类型上不存在属性'options'”但是,如果我运行,则不仅'options' 存在于'Chart' 类型上它工作正常的代码可以毫无问题地更改选项。

因此,该错误不会阻止我在“ng serve”已经运行时更改选项,但是如果我结束它并尝试重新编译,它将因上述错误而失败。

构建代码:

this.LQChart = new Chart(this.myChart, {
    type: 'bubble',
    data: {
        labels:['Jobs']
    }, options: {
        plugins:{
            colorschemes: {
                scheme: 'brewer.YlOrBr9'
            },
            zoom:{
                pan: {
                    enabled: true,
                    mode: 'xy',
                    rangeMin: {
                        x: null,
                        y: null
                    },
                    rangeMax:{
                        x: null,
                        y: null
                    }
                },
                zoom:{
                    enabled: true,
                    drag: false,
                    mode:'xy',
                    rangeMin: {
                        x: null,
                        y: null
                    },
                    rangeMax:{
                        x: null,
                        y: null
                    },
                    speed:0.1
                }
            }
        }, legend: {
            display: false
        }, title: {
            display: true,
            text: 'Location Quotient of Jobs in Region'
        }, scales: {
            yAxes: [{ 
                scaleLabel: {
                    display: true,
                    labelString: "# of Jobs"
                },
                id:'y-axis-0',
                type:'linear',
                gridLines: {
                    display:true
                },
                ticks: {
                    callback: function(value, index, values) {
                        return Number(value.toString());
                     }
                 },
                     position:'left'
             }],
             xAxes: [{
                 scaleLabel: {
                     display: true,
                     labelString: "LQ"
                 },
                 id: 'x-axis-0',
                 type: 'linear',
                 position: 'bottom',
             }]
         }, annotation: {
             annotations: [{
                 borderColor: 'black',
                 borderWidth: 2,
                 mode: 'vertical',
                 type: 'line',
                 value: 1.0,
                 scaleID: 'x-axis-0'
             }]
         }
     }
 });

要更改选项:

this.LQChart.options.scales.yAxes[0].type = 'logarithmic';

标签: htmlangularchart.js

解决方案


得到它的工作。我不知道究竟是什么导致了这个错误,但是通过将属性视为数组元素,我能够让它完美地工作。

this.LQChart['options']['scales']['yAxes'][0]['type'] = 'logarithmic';

推荐阅读