chart js react
yarn add react-chartjs-2 chart.js // npm install react-chartjs-2 chart.js
chart js react
yarn add react-chartjs-2 chart.js // npm install react-chartjs-2 chart.js
react chart js 2 api data
import React, { Component } from 'react';
import './App.css';
import axios from 'axios'
import Chart from './components/Chart';
class App extends Component {
constructor(){
super();
this.state = {
chartData:{}
}
}
componentDidMount() {
this.getChartData();
}
getChartData() {
axios.get("http://www.json-generator.com/api/json/get/coXIyroYAy?indent=2").then(res => {
const coin = res.data;
let labels = [];
let data = [];
coin.forEach(element => {
labels.push(element.labels);
data.push(element.data);
});
console.log(coin)
this.setState({
chartData: {
labels:labels,
datasets: [
{
label: "Population",
data: data,
backgroundColor: [
"rgba(255, 99, 132, 0.6)",
"rgba(54, 162, 235, 0.6)",
"rgba(255, 99, 132, 0.6)"
],
}
]
}
});
});
}
render(){
return (
<div className="App">
{Object.keys(this.state.chartData).length &&
<Chart
chartData={this.state.chartData}
location="Massachusetts"
legendPosition="bottom"
/>
}
</div>
);
}
}
export default App;
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us