使用Angular 2、chart.js和json数据的天气图
使用我从服务中收到的天气信息,我试图通过chart.js创建一个图表 我将图表导入到我的项目中,我能够使用静态数据来使用它,但我无法使用从json获得的数据 我目前正在尝试的内容如下所示:使用Angular 2、chart.js和json数据的天气图,json,angular,chart.js,angular-cli,Json,Angular,Chart.js,Angular Cli,使用我从服务中收到的天气信息,我试图通过chart.js创建一个图表 我将图表导入到我的项目中,我能够使用静态数据来使用它,但我无法使用从json获得的数据 我目前正在尝试的内容如下所示: getForeCast() { this.weatherService.getForecastByCityName(this.searchString) .subscribe(response => { this.lineChartData
getForeCast()
{
this.weatherService.getForecastByCityName(this.searchString)
.subscribe(response =>
{
this.lineChartData = response.list.main.temp;
this.lineChartLabels = response.list.dt;
})
}
//LineChart
public lineChartData: Array<any>
public lineChartLabels: Array<any>
{
"cod": "200",
"message": 0.0054,
"cnt": 35,
"list": [
{
"dt": 1498748400,
"main": {
"temp": 21.87,
"temp_min": 21.25,
"temp_max": 21.87,
"pressure": 1006.93,
"sea_level": 1009.32,
"grnd_level": 1006.93,
"humidity": 62,
"temp_kf": 0.62
},
"weather": [
{
"id": 803,
"main": "Clouds",
"description": "broken clouds",
"icon": "04d"
}
],
"clouds": {
"all": 56
},
"wind": {
"speed": 6.81,
"deg": 227.001
},
"rain": {},
"sys": {
"pod": "d"
},
"dt_txt": "2017-06-29 15:00:00"
},
如果我使用信息在表格中显示它,它会工作,但我无法使它在图表中工作。查看图表的update()
方法。也许您需要在更新数据后触发它,以便图表重新呈现