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

546
Vistas
Estilo de fondo (relleno) con ChartJs y React

Quiero crear un gráfico de líneas, con el estilo de un gráfico de área, en React usando la biblioteca chartJS ('react-chartjs-2')

Esto es lo que quiero lograr, como un fondo (relleno) con algo de opacidad debajo de la línea:

ingrese la descripción de la imagen aquí

Código:

 import React from 'react'; import { Chart as ChartJS, CategoryScale, LinearScale, PointElement, LineElement, Title, Tooltip, Legend, } from 'chart.js'; import { Line } from 'react-chartjs-2'; import faker from 'faker'; ChartJS.register( CategoryScale, LinearScale, PointElement, LineElement, Title, Tooltip, Legend ); export const options = { responsive: true, plugins: { legend: { position: 'top' as const, }, title: { display: true, text: 'Chart.js Line Chart', }, }, }; const labels = ['January', 'February', 'March', 'April', 'May', 'June', 'July']; export const data = { labels, datasets: [ { label: 'Dataset 1', data: labels.map(() => faker.datatype.number({ min: -1000, max: 1000 })), borderColor: 'rgb(255, 99, 132)', backgroundColor: '#000000', fill: { target: 'origin', above: 'rgb(255, 0, 0)', // Area will be red above the origin below: '#000000' // And blue below the origin } }, { label: 'Dataset 2', data: labels.map(() => faker.datatype.number({ min: -1000, max: 1000 })), borderColor: 'rgb(53, 162, 235)', backgroundColor: 'rgba(53, 162, 235, 0.5)', }, ], }; export function App() { return <Line options={options} data={data} />; }

¿Cómo puedo lograr esto con ChartJS ('react-chartjs-2')?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Sí, ChartJS/react-chartjs-2 admite esto. Para hacer esto, necesitas:

  1. Importe/registre el complemento chart.js Filler (mencionado en los documentos para gráficos de área )
  2. Establezca la tension de la línea (para hacer que las líneas se curven) y;
  3. Configure las opciones de fill para el conjunto de datos.

Siguiendo estos pasos esto producirá:

Ejemplo de gráfico de líneas como gráfico de áreas

Por ejemplo:

 import React from "react"; import { Line } from "react-chartjs-2"; import { Chart as ChartJS, CategoryScale, LinearScale, PointElement, LineElement, Title, Tooltip, Legend, Filler // 1. Import Filler plugin } from "chart.js"; import faker from "faker"; ChartJS.register( CategoryScale, LinearScale, PointElement, LineElement, Title, Tooltip, Legend, Filler // 1. Register Filler plugin ); export const options = { responsive: true, tension: 0.3 // 2. Set the tension (curvature) of the line to your liking. (You may want to lower this a smidge.) }; const labels = ["January", "February", "March", "April", "May", "June", "July"]; export const data = { labels, datasets: [ { label: "Dataset 1", data: labels.map(() => faker.datatype.number({ min: 0, max: 500 })), borderColor: "rgb(255, 99, 132)", backgroundColor: "rgba(255, 0, 0)", fill: { target: "origin", // 3. Set the fill options above: "rgba(255, 0, 0, 0.3)" } }, { label: "Dataset 2", data: labels.map(() => faker.datatype.number({ min: 0, max: 500 })), borderColor: "rgb(53, 162, 235)", backgroundColor: "rgba(53, 162, 235, 0.3)", fill: "origin" // 3. Set the fill options } ] }; export function App() { return <Line options={options} data={data} />; }

Código Sanbox de trabajo: https://codesandbox.io/s/chartjs-area-chart-p1o023?file=/App.tsx:817-846

about 4 years ago · Juan Pablo Isaza Denunciar
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