question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Display of tooltip changes x position of text drawn over doughnut chart.

See original GitHub issue

Using the code below I am able to draw over the center of a doughnut graph, but when tooltips are triggered the text is shifted to the left. Issue 743 got me this far and I have skimmed over the Chart.js source a few times but don’t see how I can fix this.

var canvas = document.getElementById('estimates'); var ctx = canvas.getContext('2d'); Chart.types.Doughnut.extend({ name: "DoughnutHole", initialize: function(data){ Chart.types.Doughnut.prototype.initialize.apply(this, arguments); }, draw: function(ease){ Chart.types.Doughnut.prototype.draw.apply(this, arguments); var ctx = this.chart.ctx; ctx.font = "48px serif"; ctx.fillText('Total', 95, 200); } });

var data = [ { value: 10, color:"#4E4D4A", highlight: "white", label: "Energy" }, { value: 10, color:"#4E4D4A", highlight: "white", label: "Waste Water" }, { value: 10, color: "#353432", highlight: "white", label: "Tax" }, { value: 10, color: "#94BA65", highlight: "white", label: "Water" }, { value: 10, color: "#2790B0", highlight: "white", label: "Homeowner Insurance" }, { value: 10, color: "#8FBE00", highlight: "white", label: "HOA" }, { value: 10, color: "#2B4E72", highlight: "white", label: "Other Utilities" } ];

var estimatesChart = new Chart(ctx).DoughnutHole(data, { animationEasing: "easeOutQuart",});

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
MarcisBcommented, Feb 5, 2017

I was able to fix this by calling ctx.restore(); at the beginning of the function and at the end calling ctx.save();. This ensured that the initial text position is fixed and tooltips won’t change it.

Sample code: var ctx = chart.chart.ctx; ctx.restore(); ctx.font=“20px Georgia”; ctx.fillText(“Hello World!”,10,50); ctx.save();

Btw, this issue is in version 2.4 too.

0reactions
fulldecentcommented, Jun 27, 2016

Hello, today I am closing all issues that are only affecting version 1 of Chart.js as WONTFIX.

If this issue does affect version 2 as well, I apologize for the error. Please create a test case against Chart.js 2 using on of the below websites and we will be happy to reopen the issue and update its classification:

Read more comments on GitHub >

github_iconTop Results From Across the Web

Tooltip - Chart.js
The bubble, doughnut, pie, polar area, and scatter charts override the tooltip defaults. To change the overrides for those chart types, ...
Read more >
Display text on tooltip when hover over Doughnut chart in JS
You can use the tooltip callback for this: tooltips: { callbacks: { label: (ctx, data) => (`Some text: ${data.datasets[ctx.
Read more >
How to Show Text inside or Outside Doughnut Chart on Hover ...
How to Show Text inside or Outside Doughnut Chart on Hover in Chart JSIn this video we will explore how to show text...
Read more >
How to Always Show Tooltip on Pie Chart in Chart js - YouTube
It has only one tooltip that moves to the exact location once you hover over a pie slice. This is to reduce the...
Read more >
Tooltips | Charts - Google Developers
Tooltips are the little boxes that pop up when you hover over something. (Hovercards are more general, and can appear anywhere on the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found