Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

218
Views
Cannot render data from an API using object.entries on the chart using Recharts library

I have an issue with displaying data coming from an API on the chart which is coming from Recharts library. In order to achieve that I am trying to make use of Object.entries . This is my API structure : {"deviceId":"27ff89713e684bbd8f13820c53908e79","G1HNQ3":97,"BBPF0F":-220} Values of those properties are not static and keep changing. For any advice of fixing this problem I would be very grateful,

Thank you

Please take a look at my code:

import "./App.css";
import React, { Component } from "react";
import logo from "./Logo.jpg";
import axios from "axios";
import {
  LineChart,
  Line,
  XAxis,
  YAxis,
  CartesianGrid,
  Tooltip,
  Legend,
} from "recharts";

class App extends Component {
  state = { data: [] };

  componentDidMount() {
    const dataInterval = setInterval(this.getData, 1000);
  }

  componentDidUpdate() {
    console.log(this.state.data);
  }

  
  getData = async () => {
    await axios.get("/random-data").then((res) => {
      this.setState({
        data: [
          ...this.state.data,
          res.data,
          { currentDateTime: Date().toLocaleString() },
        ],
      });
    });
  };

  renderLine = () => {
    Object.entries(this.state.data).forEach(([key, value]) => {
      Object.entries(value).forEach(([key, value]) => {
        if (key === "deviceId" || key === typeof Number) {
          return;
        }
        return <Line type="monotone" dataKey={key} stroke="red" />;
      });
      //
    });
  };

  render() {
    return (
      <div
        className="App"
        style={{
          display: "flex",
          flexDirection: "column",
          alignItems: "center",
        }}
      >
        <img src={logo} alt="BromleySat" />
        <h1 style={{ color: "green" }}>BromleySat's Serial Plotter</h1>
        <LineChart width={1000} height={300} data={this.state.data}>
          <CartesianGrid></CartesianGrid>
          <XAxis dataKey="currentDateTime"></XAxis>
          <YAxis></YAxis>
          <Tooltip></Tooltip>
          <Legend></Legend>
          {this.renderLine()}
        </LineChart>
      </div>
    );
  }
}

export default App;
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!