I
I
Ivan Shulga2020-06-28 17:01:40
React
Ivan Shulga, 2020-06-28 17:01:40

How to set path to full width and height of svg?

How to make it right so that the path in svg is the entire length and width of the svg (svg has a width and height of 100%), because I have it adaptive, as well as how to correctly flip the graph

const Chart = (props) => {

    const [data, setData] = useState([86, 32, 86, 32, 10, 84, 38, 80, 2, 100])
    const svgRef = useRef()

    useEffect(() => {
        const svg = select(svgRef.current)
        const myLine = line()
            .x((value, index) => index)
            .y(value => value)
            .curve(curveCardinal)

        svg
            .selectAll('path')
            .data([data])
            .join('path')
            .attr('d', value => myLine(value))
            .attr('fill', 'none')
            .attr('stroke', 'lavender')
            .attr('stroke-width', '2px')
    }, [data])

    return (
        <div className={s.elem}>
            <svg ref={svgRef}></svg>
        </div>
    )
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
A person from Kazakhstan, 2020-06-28
@ZamarShoo

I did not see the viewbox - write it exactly according to the size of the svg

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question