echarts-圆环图

本文介绍如何使用ECharts库创建动态更新的圆环图,包括生成随机数据、图表配置和样式设置,适用于展示实时数据变化。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

               

1、问题背景

     利用echarts制作一个圆环图,图的容器动态生成,图的数据源利用随机数动态变化,模拟后台获取数据


2、实现源码

<!DOCTYPE html><html> <head>  <meta charset="UTF-8">  <title>echarts-圆环图</title>  <link rel="shortcut icon" href="../js/echarts-2.2.7/doc/asset/ico/favicon.png">  <script type="text/javascript" src="../js/echarts-2.2.7/doc/asset/js/jquery.min.js" ></script>  <script type="text/javascript" src="../js/echarts-2.2.7/doc/example/www2/js/echarts-all.js" ></script>  <style>   body,html{    width: 99%;    height: 99%;    font-family: "微软雅黑";    font-size: 12px;   }   #pie{    width: 100%;    height: 80%;   }  </style>  <script>   $(document).ready(function(){    randomData();   });      //产生随机数   function randomData()   {    var first = (Math.random()*1000+1000).toFixed(2);    var second = (Math.random()*1000+1000).toFixed(2);    var third = (Math.random()*1000+1000).toFixed(2);    var fourth = (Math.random()*1000+1000).toFixed(2);    var chartId = Math.floor(Math.random()*1000+10000);    var pieName = ['第一季度','第二季度','第三季度','第四季度'];    var pieValue = new Array();    pieValue.push(first);    pieValue.push(second);    pieValue.push(third);    pieValue.push(fourth);    $("#bodyDiv").empty().append("<div id='pie"+chartId+"' style='width:100%;height:100%;'></div>");        buildChart(pieName,pieValue,chartId);   }      //生成圆环图   function buildChart(pieName,pieValue,chartId)   {    var pieData = new Array();    for(var i=0;i<pieName.length;i++)       {        pieData.push(eval('(' + ("{'value':"+pieValue[i]+",'name':'"+pieName[i]+"'}") + ')'));       }    var pieChart = document.getElementById("pie"+chartId);    var echart = echarts.init(pieChart);    var option =  {        title : {            text: '一年四季收入比例',            x:"center"        },        tooltip : {            trigger: 'item',            formatter: "{a} <br/>{b} : {c} ({d}%)"        },        legend: {            orient: 'horizontal',            x:"center",            y:"bottom",            data: pieName        },        series : [            {                name: '季度',                type: 'pie',                radius : ['50%','70%'],                center: ['50%', '50%'],                data:pieData,                itemStyle: {                    emphasis: {                        shadowBlur: 10,                        shadowOffsetX: 0,                        shadowColor: 'rgba(0, 0, 0, 0.5)'                    }                }            }        ]    };        echart.setOption(option);   }      //window.setInterval(randomData(),1000);  </script> </head> <body id="bodyDiv">   </body></html>

3、实现结果


           

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.youkuaiyun.com/jiangjunshow

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值