首页 前端知识 echarts入门 常用图表(柱状堆叠图)

echarts入门 常用图表(柱状堆叠图)

2024-04-16 17:04:56 前端知识 前端哥 836 683 我要收藏

echarts堆叠图柱状图的核心代码是在series中设置stack,拿官网的示例来讲,stack里内容相同的为一组堆叠
  

效果图

步骤

 步骤一:引入echarts.js

<script src="../lib/echarts.min.js"></script>

  步骤二:准备一个呈现图表的盒子

<div id="main" style="width:600px;height:400px"></div>

步骤三:初始化echarts实例对象

var chartDom = document.getElementById('main');
var myChart = echarts.init(chartDom);

步骤四:准备配置项

option = {
            // backgroud:'#333',
            tooltip: {
                trigger: 'axis',
                axisPointer: {
                type: 'shadow'
                }
            },
            legend: {},
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            xAxis: [
                {
                type: 'category',
                data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
                }
            ],
            yAxis: [
                {
                type: 'value'
                }
            ],
            series: [
                {
                    name: 'Email',
                    type: 'bar',
                    stack: 'Ad',
                    emphasis: {
                        focus: 'series'
                    },
                    data: [120, 132, 101, 134, 90, 230, 210],
                },
                {
                    name: 'Union Ads',
                    type: 'bar',
                    stack: 'Ad',
                    emphasis: {
                        focus: 'series'
                    },
                    data: [220, 182, 191, 234, 290, 330, 310],
                },
            ]
        };

步骤五:将配置项设置给echarts实例对象

option && myChart.setOption(option);

完整代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 步骤一:引入echarts.js -->
    <script src="../lib/echarts.min.js"></script>
</head>
<body>
    <!-- 步骤二:准备一个呈现图表的盒子 -->
    <div id="main" style="width:600px;height:400px"></div>
    <script>
        // 步骤三:初始化echarts实例对象
        // 参数,dom,决定图标最终呈现的位置
        var chartDom = document.getElementById('main');
        var myChart = echarts.init(chartDom);
        var option;
        var large = 0.2;
        // 步骤四:准备配置项
        option = {
            // backgroud:'#333',
            tooltip: {
                trigger: 'axis',
                axisPointer: {
                type: 'shadow'
                }
            },
            legend: {},
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            xAxis: [
                {
                type: 'category',
                data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
                }
            ],
            yAxis: [
                {
                type: 'value'
                }
            ],
            series: [
                {
                    name: 'Email',
                    type: 'bar',
                    stack: 'Ad',
                    emphasis: {
                        focus: 'series'
                    },
                    data: [120, 132, 101, 134, 90, 230, 210],
                },
                {
                    name: 'Union Ads',
                    type: 'bar',
                    stack: 'Ad',
                    emphasis: {
                        focus: 'series'
                    },
                    data: [220, 182, 191, 234, 290, 330, 310],
                },
            ]
        };
        // 步骤五:将配置项设置给echarts实例对象
        option && myChart.setOption(option);
    </script>
</body>
</html>

转载请注明出处或者链接地址:https://www.qianduange.cn//article/5064.html
标签
评论
发布的文章

用js生成小米商城

2024-04-27 21:04:59

网页汇率计算器vue代码

2024-04-26 13:04:44

Python读写Json文件

2024-04-23 22:04:19

大家推荐的文章
会员中心 联系我 留言建议 回顶部
复制成功!