Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

220
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda