-1

I have the following SVG of dynamically rendered pie chart using react-minimal-pie-chart :-

<svg viewBox="0 0 100 100" width="100%" height="100%"><path d="M 75 50 A 25 25 0 0 1 54.34120444167326 74.6201938253052" fill="none" stroke-width="50" stroke="#8dcd81"><title>Excellent</title></path><path d="M 54.34120444167326 74.6201938253052 A 25 25 0 0 1 26.507684480352285 41.449496416858295" fill="none" stroke-width="50" stroke="#eefa6b"><title>Good</title></path><path d="M 26.507684480352285 41.449496416858295 A 25 25 0 0 1 75 49.99999999999999" fill="none" stroke-width="50" stroke="#FF6382"><title>Weak</title></path><text dominant-baseline="central" x="50" y="50" dx="19.151111077974452" dy="16.06969024216348" text-anchor="middle" style="font-size: 5px;">22 %Excellent</text><text dominant-baseline="central" x="50" y="50" dx="-19.15111107797445" dy="16.069690242163485" text-anchor="middle" style="font-size: 5px;">33 %Good</text><text dominant-baseline="central" x="50" y="50" dx="4.341204441673249" dy="-24.620193825305204" text-anchor="middle" style="font-size: 5px;">44 %Weak</text></svg>

This is my Reactjs code:-

const Element = (props) => {
  return (
    <text
      dominant-baseline="central"
      x={props.x}
      y={props.y}
      dx={props.dx}
      dy={props.dy}
      text-anchor="middle"
      style={{ fontSize: "5px" }}
    >
      {`${Math.round(props.dataEntry.percentage)} %`}

      {props.dataEntry.title}
    </text>
  );
};

This is codesandbox full Reactjs example:- https://codesandbox.io/s/throbbing-moon-ejs67?file=/src/App.js

How can i line break between the texts (excellent - good ..) and their percentage .

Q8root
  • 1,243
  • 3
  • 25
  • 48

1 Answers1

0

As Danny says - just stick in a tspan. These settings seem to work ok:

const Element = (props) => {
  return (
    <text
      dominant-baseline="central"
      x={props.x}
      y={props.y}
      dx={props.dx}
      dy={props.dy}
      text-anchor="middle"
      style={{ fontSize: "5px" }}
    >
      {`${Math.round(props.dataEntry.percentage)} %`}
  <tspan dx="-12" dy="5">
      {props.dataEntry.title}
  </tspan>
    </text>
  );
};
Michael Mullany
  • 30,283
  • 6
  • 81
  • 105