Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
304 views
in Technique[技术] by (71.8m points)

angular - How to create a chart with chart.js by using data from external api

I have got some data from externel API using http get request. The code is this,

export class ProfileComponent implements OnInit {

  weather: IWeather[];

  constructor(private _weather: WeatherService) { }

  ngOnInit(): void {
    this._weather.getWeather().subscribe(data => {
      this.weather = data
    })

  }
}

The array type is IWeather which I have implemented before.It is like this,

export interface IWeather{
    sensor_id:String;
    date:String;
    data_value:String;
}

Now the thing is, I need to draw a chart using Chart.js using this data from the api(weather array). I need the key date in the X axis and the key data_value in Y axis. How to get these array values to a line chart? please help me with an example of line chart. I am a beginner in web development.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...