ChangeDetectionStrategy
到
ChangeDetectionStrategy.OnPush
,我这样做的原因是,即使没有问题,也不会持续存在,但调整大小开始滞后,并在此期间消耗更多的CPU使用量。
变更检测策略
让图表停留在第一次渲染。
另外,我得到了很多类型的图表,比如条形图,而这类图表似乎并没有出现问题,现在,它只针对我的饼图。
我的组件:
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit } from '@angular/core';
@Component({
selector: 'my-component',
templateUrl: 'my-component.html',
styleUrls: ['./my-component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class MyComponent implements OnInit {
public pieData: { category: string; value: number; active: boolean }[] = [
{category: 'Complete', value: 123},
{category: 'Work In Progress', value: 22},
{category: 'Other', value: 5},
];
constructor(private _cdRef: ChangeDetectorRef) {
}
}
<kendo-chart [seriesColors]="['orange', '#ffe', 'green']">
<kendo-chart-legend position="top"></kendo-chart-legend>
<kendo-chart-series>
<kendo-chart-series-item [type]="'pie'" [data]="pieData" [field]="'value'" [categoryField]="'category'">
</kendo-chart-series-item>
</kendo-chart-series>
</kendo-chart>
我的组件.scss
:
:host {
display: flex;
overflow: hidden;
margin: 8px;
padding: 8px;
flex-direction: column;
@media only screen and (max-width: 760px),
(min-device-width: 768px) and (max-device-width: 1024px) {
padding: 2px;
}
}