html - 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';
解决方案
得到它的工作。我不知道究竟是什么导致了这个错误,但是通过将属性视为数组元素,我能够让它完美地工作。
this.LQChart['options']['scales']['yAxes'][0]['type'] = 'logarithmic';
推荐阅读
- python - 使用 Python trace() 跟踪乘法表
- php - Laravel 5.2 使用 eloquent 方法获取每行数据的 date_diff
- jquery - Fullpage.js 调整大小时 scrollOverflow 创建错误页面视图到底部
- build.gradle - 无法从神器中取出罐子
- c++ - 如何使用参数分配回调函数
- nativescript - 图像资产和位图工厂插件之间的主要区别是什么
- c++ - 为什么我的 if 子句不起作用?如何修复变量类型?
- python - 如何在至少调用一次函数之前禁用键盘上的某个键?
- bash - 如何通过管道查找路径的基本名称
- javascript - 如何创建验证超集以扩展基本功能