react chart js 2 api data

Solutions on MaxInterview for react chart js 2 api data by the best coders in the world

showing results for - "react chart js 2 api data"
Francesca
21 Oct 2019
1import React, { Component } from 'react';
2import './App.css';
3import axios from 'axios'
4import Chart from './components/Chart';
5
6class App extends Component {
7  constructor(){
8    super();
9    this.state = {
10      chartData:{}
11    }
12  }
13
14  componentDidMount() {
15    this.getChartData();
16  }
17
18  getChartData() {
19    axios.get("http://www.json-generator.com/api/json/get/coXIyroYAy?indent=2").then(res => {
20        const coin = res.data;
21        let labels = [];
22        let data = [];
23        coin.forEach(element => {
24        labels.push(element.labels);
25        data.push(element.data);
26
27          });
28
29       console.log(coin)
30        this.setState({
31          chartData: {
32            labels:labels,
33            datasets: [
34              {
35                label: "Population",
36                data: data,
37                backgroundColor: [
38                  "rgba(255, 99, 132, 0.6)",
39                  "rgba(54, 162, 235, 0.6)",
40                  "rgba(255, 99, 132, 0.6)"
41                ],
42              }
43            ]
44          }
45        });
46      });
47    }
48
49  render(){
50
51        return (
52          <div className="App">
53          {Object.keys(this.state.chartData).length &&
54            <Chart
55              chartData={this.state.chartData}
56              location="Massachusetts"
57              legendPosition="bottom"
58            />
59          }
60          </div>
61        );
62
63    }     
64}
65
66export default App;
67
queries leading to this page
chart js 2 reacthwo to use api in simple chart reactreact chartjs 2 npmreact chart jsreact chartjs 2 documentationreact chart 2chartjs api data reactreact charts js 2react chartjs 2 set datachart js reacthow to use api for react chartuse chart js with react data from apichart js reactchartjs reactjs with apireact chart2 githubreact charjs reactreact chartjs 2 chart js chart elements get the contentreact chart js2 documentapis for chart in reactreact chart with apireact chartjs 2 using apireact charts jsreact chart 2react chartjs 2 chart js chart elementsreact chart js 2 githubinstall react chart js 2exteranl api chart js 2 reactreact chartjs 2 with an apicharte reactjs with data from api react chartjs 2 get data from apireact chartjs 2 npmdoughnut react graphjs 2 hooksreact charts js2charts js reactcharts with data from api reactreact chartjs 2 githubreact chartjschartjs reactapi data to a chart reactcreate chart based on api data in react jsreact chart2 api datareact chartjs 2 demo bar chart optionsreact chart2npm install react chartjs 2 githubreact chartjs 2 examplechartsjs2 example githubreact chartjs 2react chart js reactreact charjs 2 installreact chartjs 2 demochart js react with rest apireact charts with apireact chartjs add api dataapi data into charts reactchart js react 2react charts hsexternal api chart js 2 reactusing react chartjs with apireact chart js show api datareact chartjs projectreact chart js 2 api datareact chart js 2 example with apireact chartjs 2 chart jsreact chart js 2react chart js 2 api data