Circular meter, indicator (using a donut as an alternative to a thermometer style)
Asked Answered
R

2

9

I'm trying to show the progress of a fundraiser using some kind of donut chart. Many people use a thermometer style or progress bar for that but I really would like to get as closer as possible of something like this:

After I spent a lot of time researching I came up with a very easy solution to plot the donut using flot, here is the demo: http://jsfiddle.net/6b7nZ

$(function () {
    var data = [
    { label: "Donated", data: 20, color: '#f00' },
    { label: "Goal", data: 78, color: '#D3D3D3' }
    ];    
    $.plot($("#donut"), data,
    {
        series: {
            pie: {
                innerRadius: 0.7,
                show: true,
                label: { show: false }
            }
        },
        legend: { show: false }
    });
});

What I'm missing now is a way to add the centered label. I don't have to say that if anyone can point me to a jQuery plugin or something like that it will be even better.

Readable answered 10/3, 2012 at 20:11 Comment(1)
Surely you just put a div in the middle with a tag?Gery
F
9

Well, something like this could work. I would think that you would want to set your goal to 100, however, to make the donut look like it is reflecting the correct percentage.

HTML

<div id="donutHolder">
    <div id="donut"></div>
    <span id="donutData"></span>   
</div>

CSS

#donutHolder {
    width: 350px;
    height: 350px;
    text-align: center;
    line-height: 350px;
    font-size: 80px;
    color: #f00;
    position: relative;
}

#donut {
    width: 100%;
    height: 100%;
}

#donutData {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
    width: 100%;
}

Added JQuery

$("#donutData").text(Math.round(data[0].data/data[1].data*100)+"%");
Faultfinder answered 10/3, 2012 at 21:12 Comment(4)
@Michal: Sorry, but I'm not sure what you mean by your comment. There are no "label" elements involved in this example, so it is unclear what your issue is.Faultfinder
My problem was that i wanted to use the example together with labelsMartell
@Michal: Perhaps you should post another question, referencing this question as a cross-ref, but in yours, show exactly what you are trying to achieve with label elements (your html structure) that does not appear to be working.Faultfinder
This is fork of working code with labels active: jsfiddle.net/h4oL3dv1 ...nevertheless, i've already found another solutionMartell
G
0

I created this one useful (for me) cause this solution lets you set degrees values inside class by using less

<div class="radial_meter radial-222">
  <span class="first"><em></em></span>
  <span class="second"><em></em></span>
</div>

you can see a DEMO

Goldeneye answered 13/12, 2014 at 17:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.