echart--仪表盘

在这里插入图片描述

    var myCharts = echarts.init(document.getElementById(id));
    // var colors = ['#30BB57', '#FF9726', '#1A79FF']
    var colors = ['red', 'green', 'blue']
    var option = {
        tooltip: {
            show: false,
            formatter: '{a} <br/>{b} : {c}%'
        },
        //仪表盘起始角度。圆心 正右手侧为0度,正上方为90度,正左手侧为180度。
        series: [{
                radius: '80%',
                center: ['31%', '55%'],
                startAngle: 235,
                endAngle: 49,
                type: 'gauge',
                splitLine: {
                    show: false
                },
                axisLabel: {
                    show: false
                },
                axisTick: {
                    show: false
                },
                detail: {
                    show: false
                },
                pointer: {
                    show: false
                },
                axisLine: {
                    show: true,
                    lineStyle: {
                        width: 2,
                        type: 'dashed',
                        color: [
                            [
                                1, new echarts.graphic.LinearGradient(
                                    0, 0, 1, 0, [{
                                            offset: 0,
                                            color: '#FF9626'
                                        },
                                        {
                                            offset: 1,
                                            color: '#E7B325'
                                        }
                                    ]
                                )
                            ],
                        ]
                    }
                }
            },
            {
                radius: '62%',
                center: ['31%', '55%'],
                startAngle: 235,
                endAngle: 49,
                type: 'gauge',
                splitLine: {
                    show: true,
                    length: 5,

                    lineStyle: {
                        color: '#FF9626',
                    }
                },
                axisLabel: {
                    show: false
                },
                axisTick: {
                    show: false
                },
                detail: {
                    show: false
                },
                pointer: {
                    show: false
                },
                axisLine: {
                    show: false,
                    lineStyle: {
                        width: 2,
                        type: 'dashed',
                    }
                }
            },
            {
                name: '女生',
                type: 'gauge',
                detail: {
                    color: '#FF9626',
                    formatter: [
                        '{a|700人}',
                        '{b|女生}'
                    ].join('\n'),
                    rich: {
                        a: {
                            color: '#FF9626',
                            fontSize: 24,
                            fontWeight: 'bold',
                            lineHeight: 50
                        },
                        b: {
                            fontSize: 14,
                            color: '#C2D6E4'
                        },
                    },
                    offsetCenter: [0, '60%']
                },

                data: [{
                    value: 700,
                    name: ''
                }],
                radius: '70%',
                center: ['31%', '55%'],
                startAngle: 235,
                endAngle: 49,
                max: 1000,
                splitLine: {
                    show: false,
                },
                axisLine: {
                    show: true,
                    lineStyle: {
                        width: 8,
                        color: [
                            [
                                1, new echarts.graphic.LinearGradient(
                                    0, 0, 1, 0, [{
                                            offset: 0,
                                            color: '#FF9626'
                                        },
                                        {
                                            offset: 1,
                                            color: '#E7B325'
                                        }
                                    ]
                                )
                            ],
                        ]
                    }
                },
                axisLabel: {
                    show: false,
                },
                axisTick: {
                    show: false
                },
                pointer: {
                    length: '50%',
                },

            },

            {
                radius: '95%',
                center: ['50%', '50%'],
                startAngle: 240,
                endAngle: -60,
                type: 'gauge',
                splitLine: {
                    show: false
                },
                axisLabel: {
                    show: false
                },
                axisTick: {
                    show: false
                },
                detail: {
                    show: false
                },
                pointer: {
                    show: false
                },
                axisLine: {
                    show: true,
                    lineStyle: {
                        width: 2,
                        type: 'dashed',
                        color: [
                            [1, '#30BB57']
                        ]
                    }
                }
            },
            {
                radius: '78%',
                startAngle: 240,
                endAngle: -60,
                type: 'gauge',
                splitLine: {
                    show: true,
                    length: 5,

                    lineStyle: {
                        color: '#30BB57',
                    }
                },
                axisLabel: {
                    show: false
                },
                axisTick: {
                    show: false
                },
                detail: {
                    show: false
                },
                pointer: {
                    show: false
                },
                axisLine: {
                    show: false,
                    lineStyle: {
                        width: 2,
                        type: 'dashed',
                        color: [
                            [0.2, '#91c7ae'],
                            [0.8, '#63869e'],
                            [1, '#c23531']
                        ]
                        //   color: 'pink', 
                    }
                }
            },
            {
                name: '学生总数',
                type: 'gauge',
                detail: {
                    formatter: [
                        '{a|1500人}',
                        '{b|学生总数}'
                    ].join('\n'),
                    rich: {
                        a: {
                            color: '#00C566',
                            fontSize: 24,
                            fontWeight: 'bold',
                            lineHeight: 50
                        },
                        b: {
                            fontSize: 14,
                            color: '#C2D6E4'
                        },
                    },
                    offsetCenter: [0, '60%']
                },
                data: [{
                    value: 60,
                    name: '',
                }],
                radius: '85%',
                startAngle: 240,
                endAngle: -60,
                max: 2000,
                splitLine: {
                    show: false,
                },
                axisLine: {
                    show: true,
                    lineStyle: {
                        width: 8,
                        color: [
                            [
                                1, new echarts.graphic.LinearGradient(
                                    0, 0, 1, 0, [{
                                            offset: 0,
                                            color: '#00C566'
                                        },
                                        {
                                            offset: 1,
                                            color: '#34D07A'
                                        }
                                    ]
                                )
                            ],
                        ]
                    }
                },
                axisLabel: {
                    show: false,
                },
                axisTick: {
                    show: false
                },
                pointer: {
                    length: '50%',

                },

            },


            {
                radius: '80%',
                center: ['67%', '55%'],
                startAngle: 120,
                endAngle: -55,
                type: 'gauge',
                splitLine: {
                    show: false
                },
                axisLabel: {
                    show: false
                },
                axisTick: {
                    show: false
                },
                detail: {
                    show: false
                },
                pointer: {
                    show: false
                },
                axisLine: {
                    show: true,
                    lineStyle: {
                        width: 2,
                        type: 'dashed',
                        color: [
                            [
                                1, new echarts.graphic.LinearGradient(
                                    0, 0, 1, 0, [{
                                            offset: 0,
                                            color: '#3088FE'
                                        },
                                        {
                                            offset: 1,
                                            color: '#3088FE'
                                        }
                                    ]
                                )
                            ],
                        ]
                    }
                }
            },
            {
                radius: '62%',
                center: ['67%', '55%'],
                startAngle: 120,
                endAngle: -55,
                type: 'gauge',
                splitLine: {
                    show: true,
                    length: 5,

                    lineStyle: {
                        color: '#3088FE',
                    }
                },
                axisLabel: {
                    show: false
                },
                axisTick: {
                    show: false
                },
                detail: {
                    show: false
                },
                pointer: {
                    show: false
                },
                axisLine: {
                    show: false,
                    lineStyle: {
                        width: 2,
                        type: 'dashed',
                        // color: [
                        //     [0.2, '#91c7ae'],
                        //     [0.8, '#63869e'],
                        //     [1, '#c23531']
                        // ]
                        //   color: '#FF9626', 
                    }
                }
            },
            {
                name: '男生',
                type: 'gauge',
                detail: {
                    color: '#FF9626',
                    formatter: [
                        '{a|800人}',
                        '{b|男生}'
                    ].join('\n'),
                    rich: {
                        a: {
                            color: '#3088FE',
                            fontSize: 24,
                            fontWeight: 'bold',
                            lineHeight: 50
                        },
                        b: {
                            fontSize: 14,
                            color: '#C2D6E4'
                        },
                    },
                    offsetCenter: [0, '60%']
                },

                data: [{
                    value: 800,
                    name: ''
                }],
                radius: '70%',
                center: ['67%', '55%'],
                startAngle: 120,
                endAngle: -55,
                max: 1000,
                splitLine: {
                    show: false,
                },
                axisLine: {
                    show: true,
                    lineStyle: {
                        width: 8,
                        color: [
                            [
                                1, new echarts.graphic.LinearGradient(
                                    0, 0, 1, 0, [{
                                            offset: 0,
                                            color: '#3088FE'
                                        },
                                        {
                                            offset: 1,
                                            color: '#3088FE'
                                        }
                                    ]
                                )
                            ],
                        ]
                    }
                },
                axisLabel: {
                    show: false
                },
                axisTick: {
                    show: false
                },
                pointer: {
                    length: '50%',

                },

            }
        ],
    };
    var res = {
        ns1: 700,
        ns2: 800,
        count: 1500
    };
    if (!res.ns1 && !res.ns2 && !res.count) {
        $('#' + id).html(_err)
    } else {
        option.series[2].data[0].value = res.ns1;
        option.series[2].detail.formatter = [
                '{a|' + res.ns1 + '人}',
                '{b|女生}'
            ].join('\n'),
            option.series[2].max = res.count;
        option.series[5].data[0].value = res.count;
        option.series[5].detail.formatter = [
                '{a|' + res.count + '人}',
                '{b|学生总数}'
            ].join('\n'),
            option.series[5].max = res.count + res.count / 2;
        option.series[8].data[0].value = res.ns2;
        option.series[8].detail.formatter = [
                '{a|' + res.ns2 + '人}',
                '{b|男生}'
            ].join('\n'),
            option.series[8].max = res.count;
    }
    myCharts.setOption(option);
    window.addEventListener("resize", function () {
        myCharts.resize();
    });
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在一个页面上显示多个仪表盘,可以使用 ECharts 的 Grid 和 Multiple Axis 功能。具体步骤如下: 1. 在页面上创建一个 ECharts 实例。 2. 设置 Grid 组件的布局和位置,可以通过指定 left、right、top、bottom 等属性来实现。 3. 为每个仪表盘定义一个 Axis,可以通过设置 type 为 'value' 和 min/max 属性来指定坐标轴的范围。 4. 为每个仪表盘创建一个 Series,可以通过设置 type 为 'gauge' 和 center 属性来指定仪表盘的位置。 5. 将每个仪表盘的 Axis 和 Series 添加到 ECharts 实例中。 以下是一个示例代码片段,展示如何在一个页面上显示三个仪表盘: ``` var myChart = echarts.init(document.getElementById('main')); myChart.setOption({ grid: [ {left: '10%', top: '10%', width: '30%', height: '30%'}, {left: '50%', top: '10%', width: '30%', height: '30%'}, {left: '30%', top: '60%', width: '40%', height: '30%'} ], xAxis: [ {type: 'value', min: 0, max: 100, show: false}, {type: 'value', min: 0, max: 100, show: false}, {type: 'value', min: 0, max: 100, show: false} ], yAxis: [ {type: 'value', min: 0, max: 100, show: false}, {type: 'value', min: 0, max: 100, show: false}, {type: 'value', min: 0, max: 100, show: false} ], series: [ { type: 'gauge', center: ['25%', '25%'], axisLine: { lineStyle: { width: 10, color: [[0.2, '#228b22'], [0.8, '#48b'], [1, '#ff4500']] } }, data: [{value: 50, name: '仪表盘1'}] }, { type: 'gauge', center: ['75%', '25%'], axisLine: { lineStyle: { width: 10, color: [[0.2, '#228b22'], [0.8, '#48b'], [1, '#ff4500']] } }, data: [{value: 75, name: '仪表盘2'}] }, { type: 'gauge', center: ['50%', '75%'], axisLine: { lineStyle: { width: 10, color: [[0.2, '#228b22'], [0.8, '#48b'], [1, '#ff4500']] } }, data: [{value: 30, name: '仪表盘3'}] } ] }); ``` 在上面的代码中,我们创建了一个 3x3 的网格布局,左上角放置第一个仪表盘,右上角放置第二个仪表盘,中下部分放置第三个仪表盘。每个仪表盘都有一个 Axis 和一个 Series,其中仪表盘的位置通过 center 属性来指定。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值