Using text labels on gauges
See original GitHub issueCan I use a text label on a gauge?
I want to draw directly in the canvas. But I am using npm.
So, I forked npm and tried the following: But it does not work
This is my modified code.
GaugePointer.prototype.render = function() {
var angle, centerX, centerY, endX, endY, imgX, imgY, startX, startY, x, y;
angle = this.gauge.getAngle.call(this, this.displayedValue);
centerX = this.canvas.width / 2;
centerY = this.canvas.height * 0.9;
x = Math.round(this.length * Math.cos(angle));
y = Math.round(this.length * Math.sin(angle));
startX = Math.round(this.strokeWidth * Math.cos(angle - Math.PI / 2));
startY = Math.round(this.strokeWidth * Math.sin(angle - Math.PI / 2));
endX = Math.round(this.strokeWidth * Math.cos(angle + Math.PI / 2));
endY = Math.round(this.strokeWidth * Math.sin(angle + Math.PI / 2));
this.ctx.beginPath();
this.ctx.fillStyle = this.options.color;
this.ctx.arc(0, 0, this.strokeWidth, 0, Math.PI * 2, false);
this.ctx.fill();
this.ctx.beginPath();
this.ctx.moveTo(startX, startY);
this.ctx.lineTo(x, y);
this.ctx.lineTo(endX, endY);
this.ctx.fill();
/* ---------- Here!!!! ------- */
this.ctx.font = this.ctx.font.replace(/\d+px/, "16px");
this.ctx.fillText("Minimum", centerX / 4 - 12, this.canvas.height - 9);
this.ctx.fillText("Maximum", centerX + (centerX / 2) + 12 - 15, this.canvas.height - 9);
if (this.img) {
imgX = Math.round(this.img.width * this.options.iconScale);
imgY = Math.round(this.img.height * this.options.iconScale);
this.ctx.save();
this.ctx.translate(x, y);
this.ctx.rotate(angle + Math.PI / 180.0 * (90 + this.options.iconAngle));
this.ctx.drawImage(this.img, -imgX / 2, -imgY / 2, imgX, imgY);
return this.ctx.restore();
}
return this.ctx.fill();
};
Example I think
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:6
Top Results From Across the Web
Gauge chart with text labels for Value and Target
I would like to create a gauge chart that has text labels for the Target and Actual fields. I added text boxes to...
Read more >Tickmarks with Text | Gauge | JavaScript Wijmo Demos
Wijmo's gauges allow you to show tickmarks along their faces using the showTicks ... To add text to each tickmark, set the showTickText...
Read more >Gauges: How to add a label whose text resizes with the gauge
Hi Kevin, You can use NLength with relative unit (parent percentage) to specify the text size of the gauge label texts - for...
Read more >Highcharts Gauge Chart with text labels - Stack Overflow
You can use a yAxis.labels.formatter function to check what the label value is, and return a text of your choice depending on that...
Read more >Adding Text Labels to Numeric Objects with Scale - NI
Right-click the text display and select Visible Items»Digital Display from the shortcut menu to display the numeric values associated with the ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
See https://github.com/bernii/gauge.js/issues/4#issuecomment-7761988 for an example of how to do this. I updated it to also account for the minimum value. My use case is a gauge that shows battery voltage (in millivolts) with a label that represents it as a percentage value with 2.8 volts = 0% and 3.6 volts = 100%. Here’s my take on it.
I move out from the company that has this change. Maybe @raphaelneumann can help you.