Search code examples
csssvgrect

SVG bars graph upside down without rotation


I have an svg rect chart like:

<div style="width:300px;height:300px;">
    <svg xmlns="http://www.w3.org/2000/svg" version="1.1" style="width:100%;height:100%" viewBox="0 0 300 300">
        <g>
            <rect  width="14.55" height="40%" x="0" y="0" fill="black"></rect>
            <rect  width="14.55" height="20%" x="50" y="0" fill="green"></rect>
            <rect  width="14.55" height="80%" x="100" y="0" fill="red"></rect>
            <rect  width="14.55" height="90%" x="150" y="0" fill="yellow"></rect>
            <rect  width="14.55" height="10%" x="200" y="0" fill="pink"></rect>
            <rect  width="14.55" height="60%" x="250" y="0" fill="orange"></rect>
        </g>
    </svg> 
</div>

What I want to do is to display it upside down. The code and a given solution, are coming from http://jsfiddle.net/rhvP8/5/

Although, I want to keep each bar in the same X place. So, rotation approach is not that useful in this case.

Any help is welcome.


Solution

  • Rotation of the x-axis only seems be be what you require.

    svg {
      border: 1px solid green;
      transform: rotateX(180deg);
    }
    <div style="width:300px;height:300px;">
      <svg xmlns="http://www.w3.org/2000/svg" version="1.1" style="width:100%;height:100%" viewBox="0 0 300 300">
            <g>
                <rect  width="14.55" height="40%" x="0" y="0" fill="black"></rect>
                <rect  width="14.55" height="20%" x="50" y="0" fill="green"></rect>
                <rect  width="14.55" height="80%" x="100" y="0" fill="red"></rect>
                <rect  width="14.55" height="90%" x="150" y="0" fill="yellow"></rect>
                <rect  width="14.55" height="10%" x="200" y="0" fill="pink"></rect>
                <rect  width="14.55" height="60%" x="250" y="0" fill="orange"></rect>
            </g>
        </svg>
    </div>