Search code examples
xmlsvgrotationscalescaletransform

Rotate text in SVG


I got a chart with svg which looks like Chart

Now I want to rotate the text like Chart

My SVG root is the following

<svg xmlns="http://www.w3.org/2000/svg"
    xmlns:xlink="http://www.w3.org/1999/xlink"
    xmlns:ev="http://www.w3.org/2001/xml-events"
    version="1.1" baseProfile="full"
    viewbox="-75 0 1075 800"
    transform="translate(0, 750) scale(1, -1)"
    width="1000" height="800">
</svg>

If I try to rotate the text with

<text x="-70" y="50%" stroke="blue" transform="rotate(90)">U [mV]</text>

the text disappears.

With

<text x="-70" y="50%" stroke="blue" transform="rotate(90 -70 50%)">U [mV]</text>

nothing happens.

What have I to do to rotate the three text objects shown in the second picture? Thanks.


Solution

  • The following works for me now:

    <svg xmlns="http://www.w3.org/2000/svg"
        xmlns:xlink="http://www.w3.org/1999/xlink"
        xmlns:ev="http://www.w3.org/2001/xml-events"
        version="1.1" baseProfile="full"
        viewbox="-75 0 1075 800"
        width="1000" height="800">
    
        <g transform="translate(0, 750) scale(1, -1)"> <!-- hint from @altocumulus -->
            ...
    
            <g transform="translate(-75, 375) scale(1, -1) rotate(-90)">
                <!--
                    translate(x, y) => create a new local coordination system
                    with the point of origin at this point
                -->
    
                <text stroke="blue">U [mV]</text>
            </g>
    
            ...
        </g>
    </svg>