简体   繁体   中英

Rotating charts in Chart JS

I have a requirement for a chart that looks as such:

在此处输入图片说明

I found Chart JS' Polar Area Chart , but it's not rotated as I needed.

在此处输入图片说明

And since Chart JS doesn't seem to have a rotate property, I tried just rotating the canvas with CSS

        #myChart {
            -webkit-transform: rotate(-25.2deg);
            transform: rotate(-25.2deg);
        }

This gets the desired rotation, but as you can see, the tooltips are also shifted, and any nearby divs could be obscured by the rotated canvas:

在此处输入图片说明

Is there some feature/method I'm overlooking to rotate a polar chart without manipulating the canvas?

There's no way to rotate the chartJS but not rotate the tips :-\\

On the bright side, it's easy enough to code yourself from previous Stackoverflow posts!

A polar chart is a set of concentric wedges as shown in this Stackoverflow post:

Creating Polar Area Chart using Canvas

Tooltips are just text drawn at a specific wedge when the mouse hovers over that wedge. Here's a Stackoverflow post showing how to use context.isPointInPath to draw a tooltip if the mouse is hovering inside an irregular path (like your wedges):

HTML Canvas Hover Text

Put "rotation:90" or whichever value works the best for you. This option has been added in the last version of ChartJs

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM