showing results for - "react chartjs 2"
Alya
29 Oct 2018
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
react chartjs 2 chart js chart elementsdoughnut react graphjs 2 hooksreact chart 2react charts with apireact chartjs 2 npmreact chart js load data from apireact chart2hwo to use api in simple chart reactchart js reactreact chartjs add api datareact chartjs 2 get data from apimaking charts using api data in reactreact charjs 2 installreact chartjs 2 demoreact chart 2api data to a chart reactreact chart js reactreact chart js show api datachart js reactreact chart js 2 api datareact chart with apiapi data into charts reactreact chartjs 2 with an apireact chartjs 2 using apichartjs reactexternal api chart js 2 reactchartsjs2 example githubchart js 2 reactchartjs api data reactnpm install react chartjs 2 githubreact charjs reactreact chart js 2react chartjs 2 examplereact chartjsshow chart from api reactusing react chartjs with apiapis for chart in reactchart js react with rest apireact charts js 2react chart js 2 githubreact charts hsreact chartjs 2 chart js chart elements get the contentinstall react chart js 2use chart js with react data from apiexteranl api chart js 2 reactreact chart2 api datareact chart js 2 example with apireact chartjs 2charte reactjs with data from api react chartjs 2 demo bar chart optionscreate chart based on api data in react jsdisplay api data in chart reactchart js react 2react chartjs projectreact charts js2chartjs reactjs with apireact chartjs 2 documentationhow to use api for react chartreact chartjs 2 npmcharts js reactreact chart2 githubchartjs react with apireact charts jscharts with data from api reactreact chartjs 2 githubreact chartjs 2 chart jsreact chart jsreact chartjs 2 set datareact chart js2 documentreact chartjs 2