Drawing rotated text on a HTML5 canvas

后端 未结 5 1506
不知归路
不知归路 2020-11-28 04:06

Part of a web application I\'m developing requires me to create bar graphs to display various information. I figured, if the user\'s browser is capable, I would draw them us

5条回答
  •  日久生厌
    2020-11-28 04:27

    Like others have mentioned, you probably want to look at reusing an existing graphing solution, but rotating text isn't too difficult. The somewhat confusing bit (to me) is that you rotate the whole context and then draw on it:

    ctx.rotate(Math.PI*2/(i*6));
    

    The angle is in radians. The code is taken from this example, which I believe was made for the transformations part of the MDC canvas tutorial.

    Please see the answer below for a more complete solution.

提交回复
热议问题