zoukankan      html  css  js  c++  java
  • 通过echarts实现的刻度表Vue组件

    <template>
        <div>
            <div class="gauge-chart" ref="gaugechart"></div>
        </div>
    </template>
    
    <script>
        export default {
            name: "GaugeChart",
            data() {
                return {
    
                }
            },
            props:[
                'type'
            ],
            mounted() {
                this.draw();
            },
            methods: {
                draw() {
                    let axisTickLength = 20; //刻度线宽度
                    let value = Math.floor(Math.random() * 100)
                    let colorRegionRate = (value / 100).toFixed(2)
    
                    let index = (value >= 66 ? 0 : (value > 33 ? 1 : 2))
                    let startColor = ['#34da62', '#fed95f', '#f56c6c'][index]
                    let endColor = ['#14a661', '#ff8e02', '#f44444'][index]
    
                    let option = {
                        title: {
                            textStyle: {
                                color: '#b1977d'
                            }
                        },
                        backgroundColor: "#ffffff",
    
                        series: [{
                            type: 'gauge',
                            name: '外层半透明边框圈',
                            radius: '90%',
                            startAngle: '225',
                            endAngle: '-45',
                            splitNumber: '100',
                            pointer: {
                                show: false
                            },
                            detail: {
                                show: false,
                            },
                            axisLine: {
                                show: true,
                                lineStyle: {
                                    color: [
                                        [1, 'rgba(0,0,0,0.1)']
                                    ],
                                     8,
                                    opacity: 1
                                }
                            },
                            axisTick: {
                                show: false
                            },
                            splitLine: {
                                show: false,
                            },
                            axisLabel: {
                                show: false
                            }
                        },
                            {
                                type: 'gauge',
                                name: '第二层',
                                radius: '86%',
                                startAngle: '225',
                                endAngle: '-45',
                                splitNumber: 4,
                                pointer: {
                                    show: true,
                                    length: '53%'
                                },
                                // 仪表盘指针样式。
                                itemStyle: {
                                    color: '#000000'
                                },
                                data: [{
                                    value: value,
                                    name: '评值'
                                }],
                                title: {
                                    show: false,
                                },
                                axisLine: {
                                    show: true,
                                    lineStyle: {
                                        color: [
                                            // 有数值的部分
                                            [colorRegionRate, new this.$echarts.graphic.LinearGradient(0, 0, 1, 0, [{
                                                offset: 0,
                                                color: startColor // 0% 处的颜色
                                            },
                                                {
                                                    offset: 1,
                                                    color: endColor // 100% 处的颜色
                                                }
                                            ])],
                                            // 底色
                                            [1, new this.$echarts.graphic.LinearGradient(0, 0, 1, 0, [{
                                                offset: 0,
                                                color: 'rgba(255,255,255,0.1)' // 0% 处的颜色
                                            },
                                                {
                                                    offset: 1,
                                                    color: 'rgba(255,255,255,0.1)' // 100% 处的颜色
                                                }
                                            ])]
                                        ],
                                         50,
                                        shadowOffsetX: 0,
                                        shadowOffsetY: 0,
                                        opacity: 1
                                    }
                                },
                                axisTick: {
                                    show: false
                                },
                                splitLine: {
                                    show: false
                                },
                                detail: {
                                    show: false
                                },
                                axisLabel: {
                                    show: false,
                                },
                                animationDuration: 2000,
                            },
                            {
                                name: '第三层渐变圈',
                                type: 'gauge',
                                radius: '70%',
                                startAngle: '225',
                                endAngle: '-45',
                                splitNumber: 4,
                                pointer: {
                                    show: false
                                },
                                data: [{
                                    value: value,
                                    name: '评值'
                                }],
    
                                axisLine: {
                                    show: true,
                                    lineStyle: {
                                        color: [
                                            // 有数值的部分
                                            [colorRegionRate, new this.$echarts.graphic.LinearGradient(0, 0, 1, 0, [{
                                                offset: 0,
                                                color: startColor // 0% 处的颜色
                                            },
                                                {
                                                    offset: 1,
                                                    color: endColor // 100% 处的颜色
                                                }
                                            ])],
                                            // 底色
                                            [1, new this.$echarts.graphic.LinearGradient(0, 0, 1, 0, [{
                                                offset: 0,
                                                color: 'rgba(255,255,255,0.1)' // 0% 处的颜色
                                            },
                                                {
                                                    offset: 1,
                                                    color: 'rgba(255,255,255,0.1)' // 100% 处的颜色
                                                }
                                            ])]
                                        ],
                                         axisTickLength, // 刻度线宽度
                                        shadowOffsetX: 0,
                                        shadowOffsetY: 0,
                                        opacity: 1
                                    }
                                },
                                axisTick: {
                                    show: false
                                },
                                splitLine: {
                                    show: false,
                                },
                                // 仪表盘指针样式。
                                itemStyle: {
                                    color: '#f6fefe'
                                },
                                title: {
                                    show: false,
                                },
                                detail: {
                                    show: false
                                },
                                axisLabel: {
                                    show: false,
                                },
                                animationDuration: 2000,
                            },
                            {
                                name: '与div背景色相同模拟axisTick',
                                type: 'gauge',
                                radius: '70%',
                                startAngle: '225',
                                endAngle: '-45',
                                splitNumber: 1,
                                pointer: {
                                    show: false
                                },
                                title: {
                                    show: false,
                                },
                                detail: {
                                    show: true,
                                    offsetCenter: [0, '80%'],
                                    formatter: (value) => {
                                        return [
                                            `{a|${this.type}${value}}{b|分}`,
                                            `{c|建议${value >= 66 ? '买入' : (value > 33 ? '维持现状' : '卖出')}}`
                                        ].join('
    ')
                                    },
                                    rich: {
                                        a: {
                                            color: '#353c60',
                                            fontWeight: 500,
                                            fontSize: 14,
                                        },
                                        b: {
                                            color: '#353c60',
                                            fontWeight: 500,
                                            fontSize: 14,
                                        },
                                        c: {
                                            color: '#353c60',
                                            fontWeight: 500,
                                            fontSize: 14,
                                        },
                                    }
                                },
                                data: [{
                                    value: value,
                                    name: '评值'
                                }],
                                axisLine: {
                                    show: false,
                                    lineStyle: {
                                         1,
                                        opacity: 0
                                    }
                                },
                                axisTick: {
                                    show: true,
                                    splitNumber: 50,
                                    length: axisTickLength, // 刻度线宽度
                                    lineStyle: {
                                        // 与div背景色相同
                                        color: '#C0C0C0',
                                         1,
                                    }
                                },
                                splitLine: {
                                    show: false,
                                },
                                axisLabel: {
                                    show: false
                                }
                            },
                        ]
                    };
                    let gaugeChart = this.$echarts.init(this.$refs.gaugechart);
                    // 使用刚指定的配置项和数据显示图表。
                    gaugeChart.setOption(option);
                }
    
            }
        }
    </script>
    
    <style scoped>
        .gauge-chart {
            height: 100%;
             100%;
        }
    </style>

    参考自https://www.makeapie.com/

  • 相关阅读:
    我用纯C语言开发的中英文混合分词服务器3.0正式发布,词库190多万词,每秒切分5万+,同时提供 c、java、C#、delphi、js调用范例
    藏拙空间上线了!
    说实话我只能灌水,我谈技术你们有几个懂的啊?不信?随便发一段我写的代你们有几个能看懂的啊?
    明明三句话就能说清楚的事,专家们长篇大论,为何?
    正在开发云ERP,业务功能与天心CS ERP一模一样, 欢迎大家指正
    我的 云寻觅 搜索引擎 开始公测,前天开始开发,昨天买域名,今天发布在本机,请各路专家指正! 顺便开源!
    20071225是个值得纪念的日子,我用纯C语言开发的空间首次上线测试!
    给C# .NET 的兄弟们做点小贡献 NoSql LevelDB .net 移植版 普通PC 100万条数据插入不超过4秒
    开源:给每个文档计算一个指纹,然后用指纹进行相似度的计算 含源码和可执行程序
    国内首款完全由国人自主研发的开源云平台 BDC3.0 详解
  • 原文地址:https://www.cnblogs.com/qq965921539/p/14065117.html
Copyright © 2011-2022 走看看