EasySector 是一款基於 jQuery 的扇形餅圖插件,可以通過簡單的配置即可在頁面中渲染出美觀的百分比餅圖,並支持自定義標題、顏色、尺寸等多項參數。
查看效果:https://hovertree.com/texiao/easysector/
首先在頁面中準備一個用於承載餅圖的容器元素,然後引入 jQuery 庫與 EasySector 插件腳本:
<div id="easysector"></div> <script src="https://hovertree.com/ziyuan/jquery/jquery-2.2.0.min.js"></script> <script src="https://hovertree.com/texiao/easysector/jquery.easysector.1.0.0.js"></script>
接著準備數據數組,每一項包含標題(h_title)、數值(h_amount)與顏色(h_color)三個屬性,最後進行初始化配置:
<script>
var h_items = new Array();
h_items[0] = { "h_title": "Chrome", "h_amount": 53, "h_color": "red" };
h_items[1] = { "h_title": "FireFox", "h_amount": 16, "h_color": "yellow" };
h_items[2] = { "h_title": "IE", "h_amount": 16, "h_color": "green" };
h_items[3] = { "h_title": "Other", "h_amount": 15, "h_color": "blue" };
$("#easysector").easysector({
"h_items": h_items,
"h_title": "Browser Percent",
"h_width": 260,
"h_borderColor": "silver",
"h_poindlength": 0,
// "h_showamount": true,
"h_backColor": "#eee",
"h_recwidth": 20,
"h_titlesize": 24,
"h_Radii": 125,
"h_infosize": 16
});
</script>
h_items:餅圖數據數組,每項含標題、數值與顏色。h_title:餅圖的標題文字。h_width:整體寬度。h_borderColor:邊框顏色。h_backColor:背景顏色。h_titlesize:標題字號。h_Radii:扇形半徑。h_infosize:信息文字字號。通過調整以上參數,就能快速生成符合設計需求的扇形百分比餅圖,非常適合用於展示各類佔比數據。