angular - 如何在角度选择器中检索和覆盖预设 chart.js 选项?
问题描述
我在同一行上设置了一些带有多个 chart.js 的数据。现在,由于响应模式下的法律空间,我需要覆盖默认预设选项,所以我可以隐藏 yAxes,这对我的需要没有用。
在我用 Angular 7 编写的应用程序中,我实现了 chart.js 库,并且类型(如数据)直接在选择器中实现。
所以这就是我开始的地方:
我的 component.ts 中的默认步骤:
export class ChartJsComponent implements AfterContentInit {
@Input() public data:any;
@Input() public type:string;
@Input() width:string = '100%';
constructor(private el:ElementRef) {
}
ngAfterContentInit() {
let ctx = this.getCtx();
let data = this.data;
if(data.datasets && data.datasets.length && presets[this.type] && presets[this.type].dataset){
data.datasets = data.datasets.map((it)=>{
return Object.assign({}, presets[this.type].dataset, it)
})
}
let chart = new Chart(ctx, {
type: this.type,
data: data,
options: presets[this.type] ? presets[this.type].options : {}
});
chart.update();
}
我试过更新:
let chart = new Chart(ctx, {
type: this.type,
data: data,
options: presets[this.type] ? presets[this.type].options : {
scales: {
yAxes: {
display: false
}
}
}
});
chart.update();
我也在我的 component.html 中尝试过这种方法:
<sa-chart-js
type="pie"
[data]="{//omitted}"
[options]="[{
scales:{
yAxes:{
display: false
}
}
}]">
</sa-chart-js>
但似乎没有任何效果。
我想直接在我的选择器中覆盖该选项,但是今天我不知道该怎么做。
解决方案
xAxes
和属性是数组,yAxes
因为 chart.js 支持每个都有多个轴。您需要将代码更改为轴对象数组而不是对象。
yAxes: [{
display: false
}]
推荐阅读
- python - Weights&Biases Sweep Keras K-Fold 验证
- javascript - 使用参数的属性作为打字稿中的类型
- java - 将对象列表调用到方法中以检查枚举值
- javascript - React 等待数据从 api 获取然后发送到组件
- azure-devops - Azure DevOps API - 更改测试用例的 WorkItemType
- postgresql - 将我的 SQL Server 存储过程转换为 PostgressSQL 存储过程
- azure - 对 azure 免费层中的出站数据传输感到困惑
- c# - 从带有过滤器的目录中获取所有文件,不包括特定过滤器
- apache-kafka - Kafka Sink: ERROR 由于错误而停止 (org.apache.kafka.connect.cli.ConnectStandalone:130)
- java - 字符串长度;(vs) str.length()