Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update percentage and circle #6

Closed
fernandomatal opened this issue Mar 4, 2014 · 19 comments
Closed

Update percentage and circle #6

fernandomatal opened this issue Mar 4, 2014 · 19 comments

Comments

@fernandomatal
Copy link

Is there a way to update the percentage and the circle without re doing the circle?

I just want to update the circle every time the user performs certain action.

Thank you.

@polikin
Copy link

polikin commented Mar 14, 2014

+1

1 similar comment
@DlupBox
Copy link

DlupBox commented Mar 16, 2014

+1

@brandonzuech
Copy link

+1

@brandonzuech
Copy link

I know this isn't the answer but I would like to offer a workaround for other developers that come across this page.

[html]
<div id="statcontianer">
<div id="myStat2"></div>
</div>

[javascript]
function reset(percent)
{
$("#myStat2").remove();
$("#statcontianer").append("<div id="myStat2"></div>");
$("#myStat2").attr("data-dimension", "250");
$("#myStat2").attr("data-info", "my text");
$("#myStat2").attr("data-width", "30");
$("#myStat2").attr("data-fontsize", "38");
$("#myStat2").attr("data-fgcolor", "#61a9dc");
$("#myStat2").attr("data-bgcolor", "#eee");
$("#myStat2").attr("data-text", percent.toString());
$("#myStat2").attr("data-percent", percent.toString());
$('#myStat2').circliful();
}

@alparslanahmed
Copy link

My solution maybe not qualified but it's work for me. I'm using this with jquery downcount plugin for under construction page (http://www.dijicat.com)

function update(area, percent) {
var percent = percent;
var width = 10;
bgcolor = "#29aae2";
fgcolor = "white";
var $canvas = $("#" + area + "> canvas");
var context = $canvas[0].getContext('2d');
var x = $canvas[0].width / 2;
var y = $canvas[0].height / 2;
var degrees = percent * 360.0;
var radians = degrees * (Math.PI / 180);
var radius = $canvas[0].width / 2.5;
var startAngle = 2.3 * Math.PI;
var endAngle = 0;
var counterClockwise = false;
var circ = Math.PI * 2;
var quart = Math.PI / 2;
var fill = false;
var current = percent / 100;
context.clearRect(0, 0, $canvas[0].width, $canvas[0].height);
context.beginPath();
context.arc(x, y, radius, endAngle, startAngle, false);
context.lineWidth = width - 1;

// line color
context.strokeStyle = bgcolor;
context.stroke();

if (fill) {
    context.fillStyle = fill;
    context.fill();
}
context.beginPath();
var xd = ((circ) * current) - quart;
context.arc(x, y, radius, -(quart), xd, false);
context.lineWidth = width;
// line color
context.strokeStyle = fgcolor;
context.stroke();

};

@sQu1rr
Copy link

sQu1rr commented May 13, 2014

$('#stat').empty().removeData().attr('data-percent', '[new-percent]').circliful()

@psrebrny
Copy link

psrebrny commented Aug 3, 2014

Can i now update circle without redrawing them so if i have 14% and i want only update text in them to example 16% and draw a little circle not at begin?

@eugenio79
Copy link

Thanks so much sQu1rr!
It worked ;)

@PanRu
Copy link

PanRu commented Mar 17, 2015

Thanks so much, it helps a lot. 👍

@jpbrousseau
Copy link

Works for me! Thanks a lot!

@paddotk
Copy link

paddotk commented Mar 27, 2015

For anyone interested, I found a way to make the percentage text work as an updating counter. This will add up the displayed number along with the animating bar.
HTML
<span class="counter" id="counter1">0</span>

JS
$('#myCircle').circliful();
var updatePerc = 0;
setInterval(function(){
if(updatePerc <= 56){ //here goes the number that corresponds with "data-percent" -1
updatePerc++;
document.getElementById('counter1').innerHTML = updatePerc + '%';
}
},27); //this number depends on the value for "data-animation-step"

You'll have to position the span counter with css as well.
P.s. if anyone knows of a better way, I'd like to know!! :D

@kylescousin
Copy link

@paddotk You can just do

$('#your-circle').find('.circle-text').html(updatePerc + '%');

No css positioning needed

@paddotk
Copy link

paddotk commented Apr 1, 2015

@kylescousin This does exactly the same... Assuming the '.circle-text' still refers to the span inside the circle div?

@skinass
Copy link

skinass commented Aug 6, 2015

Here is my solution

function draw(idwhere,idwhat,options){   
    $("#"+idwhat).remove();
    $("#"+idwhere).append('<div id="'+idwhat+'"></div>');
    $.each(options, function(i, val){
        $("#"+idwhat).attr('data-'+i, val)
    });
    $("#"+idwhat).circliful();
}

A little example of using

...
draw('myStatContianer','myStat',{
    percent:'99',
    text:'99%',
    dimension: "70",
    width: "10",
    fontsize: "17",
    fgcolor: "#319db5",
    bgcolor: "#e3f5ff"
})
...

And if you dont want to redraw circles there is an extended circliful lib
Circliful-reloaded
But it has some bugs in drawing more than 2 circles

@dougwells
Copy link

sQu1rr ... worked great. Wasted several hours trying to do this myself until I found your solution. THANK YOU!

@gesaleh
Copy link

gesaleh commented Aug 17, 2016

Hi
I'm trying to make a half circle update using the sQu1rr method but it just erase and redraw a full circle with always 75% value.

is there a simple way to make the circle update ?

@IAmDarush
Copy link

To change the foreground circle degree I used the following method:

$("#circle").children("svg").eq(0).children("circle").eq(1).css("stroke-dasharray", degree + ", 20000");

where degree is the between 0 and 360. So you only update the outer circle degree without recreating the circle object.

j-m added a commit to jmsv/astonhack2017 that referenced this issue Nov 13, 2017
Circliful has a bug in updating percentages. See
pguso/js-plugin-circliful#6
@j-m
Copy link

j-m commented Nov 13, 2017

@gesaleh Same here, my solution is a combination of answers above:

var container = $('#[id]').parent();
$('#[id]').remove();
container.append('<div id="[id]" class="animate"></div>');
$("#[id]").attr("data-percent", [new percentage]);
$("#[id]").circliful();

@pguso
Copy link
Owner

pguso commented Apr 6, 2020

with the new implementation you can call the update function to set the percentage

circle.update({type: 'percent', value: 50});

@pguso pguso closed this as completed Apr 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests