Javascript 如何获取组件
如何获得“g”和“文本”的宽度,并将其用于后续计算Javascript 如何获取组件,javascript,reactjs,typescript,mobx,recharts,Javascript,Reactjs,Typescript,Mobx,Recharts,如何获得“g”和“文本”的宽度,并将其用于后续计算 const CustomizedAxisTick: React.FunctionComponent<ICustomTickProps> = ({x,y,payload,width,fill}) => { const firstLine = 12 const secondLine = 24 const dateTime = payload.value return (
const CustomizedAxisTick: React.FunctionComponent<ICustomTickProps> = ({x,y,payload,width,fill}) => {
const firstLine = 12
const secondLine = 24
const dateTime = payload.value
return (
<g transform={`translate(${x},${y})`}>
<text fontFamily="Roboto, sans-serif" transform={"rotate(-45)"} width={width} height="auto" textAnchor="middle" fontSize={12} fill={fill}>
</text>
</g>
);
}
const CustomizedAxisTick:React.FunctionComponent=({x,y,有效载荷,宽度,填充})=>{
常数firstLine=12
const secondLine=24
const dateTime=payload.value
返回(
);
}
尝试对元素使用“ref”:
从ref可以得到clientHeight/offsetHeight和clientWidth/offsetWidth。即使它们是CustomizedExistick的一部分,也可以同时得到它们吗?ref将保存DOM元素。所以,只要这个元素有高度和宽度,它就应该适合你。好的,谢谢!