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

131
Views
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 answers
Answer question

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 Report
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!