gpt4 book ai didi

angular5 - ngx图表错误 "TypeError: Object(...) is not a function"

转载 作者:行者123 更新时间:2023-12-04 05:36:19 25 4
gpt4 key购买 nike

我正在尝试在我的开发平台中实现一些统计信息,并尝试使用ngx图表来显示它们。但是我得到一个错误,我不知道为什么。

我正在使用storedProcedures获取MySQL统计信息,该统计信息是从Java Restful Backend调用的,并在Angular 5前端中将其返回。返回的表具有以下两个字段:日期和每天的事件数。因此,后端返回的表具有这两列。

我对呈现图表的组件的代码如下:

import {Component, OnInit} from '@angular/core';
import {StatisticsService} from '../../statistics.service';


class Data {

private _name: string;
private _value: number;

get name(): string {
return this._name;
}

set name(value: string) {
this._name = value;
}

get value(): number {
return this._value;
}

set value(value: number) {
this._value = value;
}

}


@Component({
selector: 'app-daily-incidents-statistics',
templateUrl: './daily-incidents-statistics.component.html',
styleUrls: ['./daily-incidents-statistics.component.css']
})


export class DailyIncidentsStatisticsComponent implements OnInit {


view: any[] = [700, 400];
data: any[] = [];

// options
showXAxis = true;
showYAxis = true;
gradient = false;
showLegend = false;
showXAxisLabel = true;
xAxisLabel = 'Ημέρα';
showYAxisLabel = true;
yAxisLabel = 'Αρ. Περιστατικών';


constructor(private statisticsService: StatisticsService) {
// Object.assign(this, { single })
// Object.assign(this, { data } );
}

colorScheme = {
domain: ['#5AA454', '#A10A28', '#C7B42C', '#AAAAAA']
};


onSelect(event) {
console.log(event);
}

async ngOnInit() {
console.log('NG ON INIT EXECUTION');
await this.getIncidentsByDay();
}

getIncidentsByDay() {
this.statisticsService.getIncidentsByDay()
.subscribe(
(results) => {
let temp = new Data();

for (let i in results) {
console.log(results[i][0] + '>>=====>> ' + results[i][1]);
temp.name = results[i][0];
temp.value = results[i][1];
this.data.push(temp);
}

const test = this.data;
// for (let i = 0; i < this.data.length; i++) {
// console.log('wtf: ' + this.data[i][0] + '::::' + this.data[i][1]);
// }
// console.log(results);
// console.log(JSON.stringify(results));
// Object.assign(this, {test});
}
);
}

}

但是,当我运行上面的代码时,我在JavaScript控制台中看到了以下错误:
ERROR TypeError: Object(...) is not a function
at BarVerticalComponent../src/common/base-chart.component.ts.BaseChartComponent.bindWindowResizeEvent (index.js:7818)
at BarVerticalComponent../src/common/base-chart.component.ts.BaseChartComponent.ngAfterViewInit (index.js:7730)
at callProviderLifecycles (core.js:12689)
at callElementProvidersLifecycles (core.js:12656)
at callLifecycleHooksChildrenFirst (core.js:12639)
at checkAndUpdateView (core.js:13794)
at callViewAction (core.js:14136)
at execComponentViewsAction (core.js:14068)
at checkAndUpdateView (core.js:13791)
at callViewAction (core.js:14136)

我的HTML模板文件:
<div>
lalalal <br/>
ante pali... <br/>
kala ti na pw... <br/>
Gamiete pali... <br/>
<ngx-charts-bar-vertical
[view]="view"
[scheme]="colorScheme"
[results]="data"
[gradient]="gradient"
[xAxis]="showXAxis"
[yAxis]="showYAxis"
[legend]="showLegend"
[showXAxisLabel]="showXAxisLabel"
[showYAxisLabel]="showYAxisLabel"
[xAxisLabel]="xAxisLabel"
[yAxisLabel]="yAxisLabel"
(select)="onSelect($event)">
</ngx-charts-bar-vertical>
</div>

检索值的服务是:
import {Injectable} from '@angular/core';
import {HttpClient} from '@angular/common/http';
import {catchError} from 'rxjs/operators';
import {ErrorHandler} from '../shared/lib/error-handler';
import {Observable} from 'rxjs/Observable';

@Injectable()
export class StatisticsService {

constructor(private http: HttpClient) {
}


public getIncidentsByDay(): Observable<any> {
console.log("FEtching Incidents All By Day");
const url = 'statistics/incidents/day';
return this.http.get(url)
.pipe(catchError(ErrorHandler.handleError));
}
}

我究竟做错了什么?

最佳答案

我使用的是Angular 5.3版和ngx-charts 8.0,它们与Angular 6兼容,而不是与Angular 5兼容。我安装了ngx-charts 7.4版,并且一切正常。

关于angular5 - ngx图表错误 "TypeError: Object(...) is not a function",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50407259/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com