我有一个现有的散点图,可使用API中的值显示该图。我想用此代码添加折线图。帮助我实现这一目标。这是我的图形component.ts代码。我添加了带有一些样本值的折线图数据系列,这样做会折叠整个图形,并且图形图会在一个空格中弄乱。
public options: any = {
chart: {
type: 'scatter',
height: 500
},
title: {
text: ''
},
credits: {
enabled: false
},
tooltip: {
formatter: function() {
return 'x: ' + Highcharts.dateFormat('%e %b %y %H:%M:%S', this.x) +
' y: ' + this.y.toFixed(2);
}
},
xAxis: {
type: 'datetime',
},
series: [
{
name: 'SaleDate',
turboThreshold: 500000,
data: [],
},
{
name: 'SalePrice',
turboThreshold: 500000,
data: [],
}
]
}
subscription: Subscription;
constructor(private http: HttpClient) {
}
ngOnInit(){
this._dataService.onSubmit
.pipe(takeUntil(this.ngUnSubscribe))
.subscribe(response => {
this.value = response;
});
// Sample API
const apiLink = 'https://api.myjson.com/bins/13lnf4';
this.getApiResponse(apiLink).then(
data => {
const updated_normal_data = [];
const updated_abnormal_data = [];
data.forEach(row => {
const temp_row = [
new Date(row.timestamp).getTime(),
row.value,
];
row.SellerContribution === 0 ? updated_normal_data.push(temp_row) : updated_abnormal_data.push(temp_row);
});
this.options.series[0]['data'] = updated_normal_data;
this.options.series[1]['data'] = updated_abnormal_data;
Highcharts.chart('container', this.options);
},
error => {
console.log('Something went wrong.');
})
}
getApiResponse(url) {
return this.http.get<any>(url, {})
.toPromise().then(res => {
return res;
});
}
}
我尝试了链接https://jsfiddle.net/gh/get/library/pure/highcharts/highcharts/tree/master/samples/highcharts/demo/combo-regression/中指定的折线图选项。但它搞砸了。