加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angular – ngx图表数据与管道

发布时间:2020-12-17 06:59:47 所属栏目:安全 来源:网络整理
导读:我正在使用带有ngx-charts数据数组的过滤器管道.数据按2个日期过滤:fromDate和toDate.当使用使数组变小的日期进行过滤时,管道工作正常,但是当我首先使用较小的日期范围过滤然后再次使范围变大时,管道不能与原始数组一起使用,而是使用已经过滤的数组. 我已经
我正在使用带有ngx-charts数据数组的过滤器管道.数据按2个日期过滤:fromDate和toDate.当使用使数组变小的日期进行过滤时,管道工作正常,但是当我首先使用较小的日期范围过滤然后再次使范围变大时,管道不能与原始数组一起使用,而是使用已经过滤的数组.

我已经做了其他的点子,从来没有遇到过这个问题,我不确定这里出了什么问题.也许有人可以帮助我.

管:

export class DateInRangePipe implements PipeTransform {
    transform(obj: any[],from: Date,to: Date): any[] {
        if (obj && from && to) {
            obj.forEach(data => {
                data.series = data.series.filter((item: any) => {
                    return this.inRange(item.name,from,to);
                });
            });
        }
        return [...obj];
    }

    inRange(date: Date,to: Date): boolean {
        return date.getTime() >= from.getTime() &&
            date.getTime() <= to.getTime() ? true : false;
    }
}

Chart.component.html部分

<ngx-charts-line-chart
    [view]="view"
    [scheme]="colorScheme"
    [results]="multi | dateinrangePipe: from: to"
    [gradient]="gradient"
    [xAxis]="showXAxis"
    [yAxis]="showYAxis"
    [legend]="showLegend"
    [showXAxisLabel]="showXAxisLabel"
    [showYAxisLabel]="showYAxisLabel"
    [xAxisLabel]="xAxisLabel"
    [yAxisLabel]="yAxisLabel"
    [autoScale]="autoScale"
    (select)="onSelect($event)">
</ngx-charts-line-chart>

解决方法

`data.series = data.series.filter...`

是对原始对象的引用.要打破引用,必须在开头创建obj数组的克隆.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读