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

129
Vistas
Find A Middle Date Between Two Dates in D3.js

I am using a D3.js scatterplot to show amount of works according to time periods. I would like to place points at the middle date between the beginning and ending dates for each period. The data I have looks like this:

period, amount, startDate, endDate
1, 5, 26/11/1982, 2/6/1989
2, 6, 2/6/1989,2/1/1990
3, 11, 2/01/1990,20/6/1999

I tried mapping points on the graph using:

.attr("cx", function(d) { return xScale(new Date(d.endDate)) - xScale(new Date(d.startDate)) * 0.5 })

But this doesn't work. What am I missing?

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

0

The middle point between two given points is:

middleX = (x1 + x2) / 2;

In your case:

d => {
  const xFrom = xScale(new Date(d.startDate));
  const xTo = xScale(new Date(d.endDate));
  return (xFrom + xTo) / 2;
}
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