canvas fill text vanishes when hovering over chartjs pie chart

前端 未结 3 1669
心在旅途
心在旅途 2021-01-15 05:21

I am using a doughnut chart from chartjs, and in the center of this canvas I am filling two lines of text. These show up fine after the initial animation, but when I hover o

3条回答
  •  甜味超标
    2021-01-15 05:40

    ChartJS will redraw itself as needed (for example when displaying tooltips), so you must redraw your "% and responses" text whenever ChartJS refreshes (redraws) the chart.

    You can set ChartJS's 'onAnimationComplete' callback to draw your call your "% and responses" text when ChartJs has completed it's own drawing and animating.

    [ Addition: ]

    I've taken a look at the ChartJS source code and the Issues on Github.

    There is currently no way within the ChartJS API to trigger redraws of your custom text (your "% and responses") after a tooltip closes.

    One workaround would be to use CSS to place a div with your "% and responses" over the chart.

提交回复
热议问题