Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

api call in react chart

import axios from "axios";
import React,{useEffect, useState} from "react";
import {Bar, BarChart, CartesianGrid, Legend, Tooltip, XAxis, YAxis} from 'recharts'

function Analytics() {

  const [data,setData] = useState();

  useEffect(() => {

  axios.get('https://iammaawesomee.herokuapp.com/data/get-data').then(function(response){
/*Change the api bcuz this is fake api and setup the response data by consoling output */
  
    console.log(response.data)
    /* Response.data in this case is an array of objects.. so keep in mind*/
  
    setData(response.data)
}).catch(function(error){
  console.log(error);
})


}, []);



  return (
      <>
      <div style={{marginTop:'50px',marginLeft:'125px',marginBottom:'60px'}}>
        <h1 style={{marginLeft:'-130px',marginBottom:'30px',color:'red'}}>Data Analytics</h1>
<BarChart width={1000} height={300} data={data}>
  <CartesianGrid strokeDasharray="1 1" />
  <XAxis dataKey="device_id" />
  <YAxis />
  <Tooltip />
  <Bar dataKey="distanceCm" fill="#8884d8" />
  <Bar dataKey="duration" fill="#82ca9d" />
  <Bar dataKey="Perc" fill="#82ea5d" />
  <Legend />

</BarChart></div>
      </>
    );
  }

export default Analytics;


/*(((then u need to import this file in app.js file )))*/
Comment

PREVIOUS NEXT
Code Example
Javascript :: observables loop in template angular 8 
Javascript :: Using toLocaleString() to Print JavaScript Number Format with Commas 
Javascript :: Automatically Refresh or Reload a Page using http-equiv 
Javascript :: Private Class Methods and Accessors in es12 
Javascript :: Example to adds two colour palettes to the sidebar in wordpress 
Javascript :: Array helper functions in ES6 
Javascript :: show route between markers google maps javascript 
Javascript :: convert fetch in axios 
Javascript :: material ui table row onclick 
Javascript :: js regexp eth wallet 
Javascript :: find a node that match a spesific selector string in the paren 
Javascript :: nestjs cors dotnot woriking 
Javascript :: django formdata use csrf token in js 
Javascript :: socket io import es6 
Javascript :: date javascript only show day month year 
Javascript :: console form elememts as json object 
Javascript :: convert base64 to image javascript 
Javascript :: how to remove all Class(es) from a DOM, and then adds all Elements of an Array 
Javascript :: trackpad scrolling detected multiple times 
Javascript :: React img element rating 
Javascript :: Unhandled Navigation Error: angular dist build 
Javascript :: angular 10 filter date time 
Javascript :: serve public folder express without file extension 
Javascript :: span color 
Javascript :: Arrays in Apps Script 
Javascript :: Remove all index from array except the one jquery 
Javascript :: Reading manifest: Warning processing Description: An unexpected property was found in the WebExtension manifest. 
Javascript :: Arr::get() The Arr::get method retrieves a value from a deeply nested array using "dot" notation: 
Javascript :: javascript reflections iterate all members 
Javascript :: non-arrow functions are forbidden $(document).ready(function() { 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =