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

156
Vistas
How to show data with no variation with Linear Gradient using Rechart?

I want to show data fetched from an API in line chart using rechart.But if there is no variation in the datapoint ('pv' in our case) then no graph line is visible when using linear gradient, but I want a single line in case of no variation in the data point. Assume data is fetched from an API and can be dynamic

import { LineChart, Line, Tooltip, XAxis } from "recharts";
import ReactDOM from "react-dom";
import React from "react";

const data = [
  { name: "Page A", uv: 4000, pv: 1000, amt: 2400 },
  { name: "Page B", uv: 3000, pv: 1000, amt: 2210 },
  { name: "Page C", uv: 2000, pv: 1000, amt: 2290 },
  { name: "Page D", uv: 2780, pv: 1000, amt: 2000 },
  { name: "Page E", uv: 1890, pv: 1000, amt: 2181 },
  { name: "Page F", uv: 2390, pv: 1000, amt: 2500 },
  { name: "Page G", uv: 3490, pv: 1000, amt: 2100 }
];

const App = () => {
  return (
    <LineChart width={500} height={500} data={data}>
      <defs>
        <linearGradient id="colorUv" x1="0%" y1="0" x2="100%" y2="0">
          <stop offset="0%" stopColor="blue" />
          <stop offset="50%" stopColor="red" />
          <stop offset="100%" stopColor="red" />
        </linearGradient>
      </defs>
      <Line
        type="monotone"
        dataKey="pv"
        stroke="url(#colorUv)"
        strokeWidth={3}
        dot={false}
        activeDot={false}
      />
      <XAxis />
      <Tooltip />
    </LineChart>
  );
};

ReactDOM.render(<App />, document.getElementById("root"));
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