RGraph : svg : 饼图

www.rgraph.net下载RGraph.minified-2018-08-14.zip

解压后,将目录libraries简化为:lib

饼图例子:RGraph/svg_pie1.html

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>RGraph : SVG Pie charts API </title>
  <script src="./lib/RGraph.svg.common.core.js"></script>
  <script src="./lib/RGraph.svg.common.key.js"></script>
  <script src="./lib/RGraph.svg.common.tooltips.js"></script>
  <script src="./lib/RGraph.svg.pie.js"></script>
</head>
<body>
  <div style="width: 850px; height: 350px" id="chart-pie"></div>
  <div id="tab"></div>
<script>
    var data   = [20,13.43,2.83,4.24,7.42,13.43,38.65];
    var labels = ['Miscellaneous','Cooking','Office equipment','Refridgeration','Cooling','Ventilation','Lighting'];
    var tips =  new Array();
    for (var i=0; i<data.length; i++) {
        tips[i] = labels[i] + ', ' + data[i] + '%';
    }
    var colors = ['#EC0033','#A0D300','#FFCD00','#00B869','#999999','#FF7300','#004CB0'];

    var pie = new RGraph.SVG.Pie({
        id: 'chart-pie',
        data: data,
        options: {
            labels: labels,
            tooltips: tips,
            colors: colors,
            strokestyle: 'white',
            linewidth: 2,
            shadow: true,
            shadowOffsetx: 2,
            shadowOffsety: 2,
            shadowBlur: 3,
            exploded: 7
        }
    }).draw();
// create table
    var table = document.createElement("table");
    table.border = "1"; // table.width = "100%";
    var tb = document.createElement("tbody");
    table.appendChild(tb);
    var tr,td;
    tr = tb.insertRow(0); // 创建第一行
    for(var j=0; j<labels.length; j++){
        td = tr.insertCell(tr.cells.length);
        td.innerHTML = labels[j];
        td.align = "center";
    }
    tr = tb.insertRow(tb.rows.length); // 创建一行
    for(var j=0; j<data.length; j++){
        td = tr.insertCell(tr.cells.length);
        td.innerHTML = data[j] +'%';
        td.align = "center";
    }
    document.querySelector("#tab").appendChild(table);   
</script>
</body>
</html>

相关推荐