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

327
Views
d3.js Donut chart only draws a single cutoff slice inside a react component

I have made a piechart in javascript and I'm now trying to bring it inside a react component. However, it only draws a single slice and that one isn't even complete it's cutoff. Here are images of the cut off slice from the react component and how it looks just rendering in html.

screeenshot
same code rendered with javascript and html

I am not sure why.

This is my function drawing it:

  function drawDonut(inputData: DealNumbers[]) {
const radius = Math.min(width, height) / 2;

const color = d3.scaleOrdinal(d3.schemeCategory10);

const arc = d3.arc()
  .outerRadius(radius - margin.top)
  .innerRadius(radius - radius * 0.5);

const pie = d3
  .pie()
  .padAngle(0)
  .value((d) => d.deals);

svg
  .attr('width', width + margin.left + margin.right)
  .attr('height', height + margin.top + margin.bottom)
  .append('g')
  .attr('transform', `translate(${(width / 2) + margin.left}, ${(height / 2) + margin.top})`);

svg
  .selectAll('.arc')
  .data(pie(inputData))
  .enter()
  .append('g')
  .attr('class', 'arc')
  .append('path')
  .attr('d', arc)
  .style('fill', (d) => color(d.data.name)); 

It is pretty much the same except that I'm using a svg view box and I pass width and height as props instead of hardcoding it. It draws perfectly fine from a javascript.

Thanks for any hints and tips you are able and take the time to give!

Best Regards,

Oliver

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

The issue was with the view box (moving the origin from 0,0 to -width, -height worked), a workaround for some reason I have had to copy intermediate variables

const pwidth = width
const pheight = height

and use these instead of width. Then I don't need to adjust the viewboxs origin. Which is a bit strange to say the least. I won't accept this answer here as I have no idea why. But adding it so someone else may find an answer if they're looking for it.

about 4 years ago · Santiago Trujillo 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!