bernii / gauge.js

100% native and cool looking JavaScript gauge
MIT License
1.42k stars 391 forks source link

Percentage #4

Closed orefalo closed 12 years ago

orefalo commented 12 years ago

Very neat project, congrats.

what about a percentage rather than the actual gauge value ?

bernii commented 12 years ago

I've added a helper class that wraps text div to help you customize the rendering of the text field. Here you can find a simple source code (JavaScript) that converts gauge value to percentage :)

gauge = new Gauge(target).setOptions(opts);

var textRenderer = new TextRenderer(document.getElementById('preview-textfield'))
textRenderer.render = function(gauge){
   percentage = gauge.displayedValue / gauge.maxValue
   this.el.innerHTML = (percentage * 100).toFixed(2) + "%"
};
gauge.setTextField(textRenderer);
singhkumarhemant commented 5 years ago

it worked for me....thanks

danielsegg commented 3 years ago

Muito obrigado. Funcionou perfeitamente pra mim. Eu usei para valor monetário. Deixo o código para ajudar outros Devs.

let textRenderer = new TextRenderer(document.getElementById("preview-textfield"))
textRenderer.render = function(gauge) {
    this.el.innerHTML = "R$ " + gauge.displayedValue.toLocaleString("pt-BR");
};
gauge.setTextField(textRenderer);