Chart.options返回“类型'图表'上不存在属性'选项'”

时间:2019-06-27 10:13:17

标签: html angular chart.js

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

因此,该错误不会阻止我在已运行“ 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';

1 个答案:

答案 0 :(得分:0)

使其正常工作。 我不知道是什么导致了此错误,但是通过将属性视为数组元素,我能够使其工作正常。

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