admin管理员组文章数量:1277885
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:
$(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.
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/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.
Share Improve this question edited May 12, 2016 at 15:58 Jason Aller 3,65228 gold badges41 silver badges39 bronze badges asked Mar 10, 2012 at 20:11 CodeMaster2008CodeMaster2008 9212 gold badges13 silver badges25 bronze badges 1- Surely you just put a div in the middle with a tag? – jacktheripper Commented Mar 10, 2012 at 20:24
2 Answers
Reset to default 9Well, 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)+"%");
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
本文标签:
版权声明:本文标题:javascript - Circular meter, indicator (using a donut as an alternative to a thermometer style) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741291702a2370588.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论