使用angular 4中的贴图操作符指定对象
我需要使用数组将一个对象映射到另一个对象。如何在第四章中实现这一点。目前,我正在使用forEach循环将项目推送到数组中。我需要用地图来代替使用angular 4中的贴图操作符指定对象,angular,highcharts,Angular,Highcharts,我需要使用数组将一个对象映射到另一个对象。如何在第四章中实现这一点。目前,我正在使用forEach循环将项目推送到数组中。我需要用地图来代替 export interface GraphConfiguration { seriesName: string; color: string; } export interface StressTestAnalysis extends GraphConfigur
export interface GraphConfiguration {
seriesName: string;
color: string;
}
export interface StressTestAnalysis extends GraphConfiguration {
curlevel: number;
decrease: number;
increase: number;
yaxis: number[];
data: number[];
}
public results: Array<StressTestAnalysis> = [];
private _stressResults: Array<StressTestAnalysis> = [];
@Input() set stressResults(value: Array<StressTestAnalysis>) {
this._stressResults = value;
this.addSeries();
let minY = Math.min(...this.yAxisSeries.map(el => Math.min(...el.yaxis)));
let maxY = Math.max(...this.yAxisSeries.map(el => Math.max(...el.yaxis)));
this.generateYAxisArray(minY, maxY);
}
this.results.forEach(element => {
if (element.data !== null)
this.chartSeries.push({ data: element.data, name: element.seriesName, color: element.color });
if (element.yaxis !== null)
this.yAxisSeries.push({ yaxis: element.yaxis });
});
private addSeries() {
if (this._stressResults === null) {
return;
}
private generateYAxisArray(min: any, max: any) {
let count = min;
for (count = min; count <= max; count = count + 500000) {
this.yAxisData.push(count);
}
}
直方图分量码
<div *ngIf="!showTable" class="tab-pane base-strategy-chart fade show active" id="base-strategy-chart--nva" role="tabpanel"
aria-labelledby="chart-tab">
<div class="tb-container">
<div class="tb-row d-flex flex-row">
<div class="tb-cell col-12 pt-5">
<splinechart [series]="chartSeries" [yaxisdata]="yAxisData">
</splinechart>
</div>
</div>
</div>
试试这个
var numbers = [1, 4, 9];
this.results = this.numbers.map((result) => {
console.log('Your result:', result);
// Add your business logic to modify result
new_result = result + 1
return new_result;
});
console.log('Your final results array:', this.results);
什么是chartSeries和yAxisSeries?
map
是否必须返回此值?是,样条曲线图组件需要这两个对象。我已经更新了帖子,展示了绑定是如何完成的。查看代码行我认为我的解决方案将返回results对象,我可以这样做您可以使用这个var result=this.result.reduce((r,o)=>{if(o.data)r.chartSeries.push({data:o.data,name:o.seriesName,color:o.color});if(o.yaxis)r.yaxis.push({yaxis:o.yaxis});返回r;{chartSeries:[],yAxisSeries:[]})
我收到以下错误编译器。es5.js:14985错误类型错误:无法读取SplineChartComponent.webpackJsonp…/../../../../../../../../../../src/app/shared/Highcharts/spline/spline上未定义的属性“map”。请注意,我的结果对象应同时包含对象chartseries和yaxisarray
var numbers = [1, 4, 9];
this.results = this.numbers.map((result) => {
console.log('Your result:', result);
// Add your business logic to modify result
new_result = result + 1
return new_result;
});
console.log('Your final results array:', this.results);