echarts3 环形图示例(13)

2018年06月21日 11:54 | 3119次浏览 作者原创 版权保护

好久没更新百度echarts的实例了,今天抽空在更新一篇实例吧,本章节介绍echarts的环形图实例,步骤如下

环形图实例

1,新建静态页面demo.html,并引入echarts的js库,在这里我们引入的是网络地址

<script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/echarts/echarts-all-3.js"></script>

2,环形图容器html代码,只需一行html代码

<div id="container" style="height: 500px"></div>

环形容器高度为500px,宽度默认,并且div的id号为container,在接下来初始化环形图的时候会用到。

3,javascript实现代码

<script type="text/javascript">
var dom = document.getElementById("container");
var myChart = echarts.init(dom);
var app = {};
var option = null;
app.title = '环形图';

option = {
    tooltip: {
        trigger: 'item',
        formatter: "{a} <br/>{b}: {c} ({d}%)"
    },
    legend: {
        orient: 'vertical',
        x: 'left',
        data:['直接访问','邮件营销','联盟广告','视频广告','搜索引擎']
    },
    series: [
        {
            name:'访问来源',
            type:'pie',
            radius: ['50%', '70%'],
            avoidLabelOverlap: true,
            label: {
                normal: {
                    show: true,
                    position: 'center'
                },
                emphasis: {
                    show: true,
                    textStyle: {
                        fontSize: '30',
                        fontWeight: 'bold'
                    }
                }
            },
            labelLine: {
                normal: {
                    show: false
                }
            },
            data:[
                {value:335, name:'直接访问88%'},
                {value:310, name:'邮件营销'},
                {value:234, name:'联盟广告'},
                {value:135, name:'视频广告'},
                {value:1548, name:'搜索引擎'}
            ]
        }
    ]
};

 
 
 
if (option && typeof option === "object") {
    myChart.setOption(option, true);
}
       </script>

4,用浏览器打开demo.html,效果如下

5,demo.html完整代码

<!DOCTYPE html>
<head>
       <meta charset="utf-8">
   </head>
   <body >
       <div id="container" style="height: 500px"></div>
        
       <!-- V型知识库 www.vxzsk.com -->
        
       <script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/echarts/echarts-all-3.js"></script>
        
       <script type="text/javascript">
var dom = document.getElementById("container");
var myChart = echarts.init(dom);
var app = {};
var option = null;
app.title = '环形图';

option = {
    tooltip: {
        trigger: 'item',
        formatter: "{a} <br/>{b}: {c} ({d}%)"
    },
    legend: {
        orient: 'vertical',
        x: 'left',
        data:['直接访问','邮件营销','联盟广告','视频广告','搜索引擎']
    },
    series: [
        {
            name:'访问来源',
            type:'pie',
            radius: ['50%', '70%'],
            avoidLabelOverlap: true,
            label: {
                normal: {
                    show: true,
                    position: 'center'
                },
                emphasis: {
                    show: true,
                    textStyle: {
                        fontSize: '30',
                        fontWeight: 'bold'
                    }
                }
            },
            labelLine: {
                normal: {
                    show: false
                }
            },
            data:[
                {value:335, name:'直接访问88%'},
                {value:310, name:'邮件营销'},
                {value:234, name:'联盟广告'},
                {value:135, name:'视频广告'},
                {value:1548, name:'搜索引擎'}
            ]
        }
    ]
};

 
 
 
if (option && typeof option === "object") {
    myChart.setOption(option, true);
}
       </script>
   </body>
</html>



小说《我是全球混乱的源头》
此文章本站原创,地址 https://www.vxzsk.com/1099.html   转载请注明出处!谢谢!

感觉本站内容不错,读后有收获?小额赞助,鼓励网站分享出更好的教程