美文网首页
echarts 图标的小案例

echarts 图标的小案例

作者: 家乡_a6ce | 来源:发表于2021-08-04 17:32 被阅读0次
    <template>
        <div style="font-size: 24px ;margin: 50px">
            <div>{{$store.state.count}}</div>
            <countTo :startVal='startVal' :endVal='endVal' :duration='2000'></countTo>
            <div>
                <div id="myChart" :style="{width: '300px', height: '300px'}"></div>
                <div id="myChart1" :style="{width: '500px', height: '500px'}"></div>
                <div id="myChart2" :style="{width: '500px', height: '500px'}"></div>
                <div id="myChart3" :style="{width: '700px', height: '400px'}"></div>
            </div>
        </div>
    </template>
    
    <script>
        import countTo from 'vue-count-to';
    
        export default {
            name: "page5-4",
            components: {countTo},
            data() {
                return {
                    startVal: 0,
                    endVal: 2017
                }
            },
            mounted() {
                this.drawLine();
            },
            methods: {
                drawLine() {
                    // 基于准备好的dom,初始化echarts实例
                    let myChart = this.$echarts.init(document.getElementById('myChart'))
                    let myChart1 = this.$echarts.init(document.getElementById('myChart1'))
                    let myChart2 = this.$echarts.init(document.getElementById('myChart2'))
                    let myChart3 = this.$echarts.init(document.getElementById('myChart3'))
                    // 绘制条形图表
                    myChart.setOption({
                        title: {text: '在Vue中使用echarts'},
                        tooltip: {},
                        xAxis: {
                            data: ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
                        },
                        yAxis: {},
                        series: [{
                            name: '销量',
                            type: 'bar',
                            data: [5, 20, 36, 10, 10, 20]
                        }]
                    });
                    // 绘制饼形图表
                    myChart1.setOption({
                        title: {
                            text: '某站点用户访问来源',
                            subtext: '纯属虚构',
                            left: 'center'
                        },
                        tooltip: {
                            trigger: 'item',
                            formatter: '{a} <br/>{b} : {c} ({d}%)'
                        },
                        legend: {
                            orient: 'vertical',
                            left: 'left',
                            backgroundColor: '#e3e3e3',
                        },
                        series: [
                            {
                                name: '访问来源',
                                type: 'pie',
                                // radius: '50%',
                                radius: ['40%', '70%'],
                                // 扇形边框
                                itemStyle: {
                                    borderRadius: 10,
                                    borderColor: '#fff',
                                    borderWidth: 2
                                },
                                data: [
                                    {value: 1048, name: '搜索引擎'},
                                    {value: 735, name: '直接访问'},
                                    {value: 580, name: '邮件营销'},
                                    {value: 484, name: '联盟广告'},
                                    {value: 300, name: '视频广告'}
                                ],
                                emphasis: {
                                    itemStyle: {
                                        shadowBlur: 10,
                                        shadowOffsetX: 0,
                                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                                    }
                                }
                            }
                        ]
                    });
                    // 绘制折现
                    myChart2.setOption({
                        title: {
                            text: '未来一周气温变化',
                            subtext: '纯属虚构'
                        },
                        legend: {
    
                        },
                        toolbox: {
                            feature: {
                                // 折线和条形图的切换
                                magicType: {type: ['line', 'bar']},
                                // 下载图形png格式
                                saveAsImage: {},
                                // 刷新
                                restore: {},
                                // 转成文本
                                dataView: {readOnly: false},
                            }
                        },
                        // 鼠标移上去弹框提示
                        tooltip: {
                            trigger: 'axis'
                        },
                        xAxis: {
                            type: 'category',
                            boundaryGap: false,
                            data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
                        },
                        yAxis: {
                            type: 'value',
                            // y轴的字段修改
                            axisLabel: {
                                formatter: '{value} °C',
                                // 控制Y轴字体大小和颜色
                                textStyle: {
                                    fontSize: '8', // 控制Y轴label字体大小
                                    color: 'red', // 控制Y轴label字体颜色
                                },
                            }
                        },
                        grid: {
                            left: '1%',
                            right: '7%',
                            bottom: '10%',
                            containLabel: true,
                        },
                        series: [{
                            name: '温度',
                            data: [150, 230, 224, 218, 135, 147, 860],
                            type: 'line',
                            // smooth: true,  //基础平滑折现
                            areaStyle: {}, // 基础面积图
                            markPoint: {
                                data: [
                                    {type: 'max', name: '最大值'},
                                    {type: 'min', name: '最小值'}
                                ]
                            },
                            markLine: {
                                data: [
                                    {type: 'average', name: '平均值'}
                                ]
                            }
                        }]
                    });
                    myChart3.setOption({
                        title: {
                            text: '折线图堆叠',
                            subtext: '折线图堆叠'
                        },
                        tooltip: {
                            trigger: 'axis'
                        },
                        legend: {
                            data: ['邮件营销', '联盟广告', '视频广告', '直接访问', '搜索引擎']
                        },
                        grid: {
                            left: '3%',
                            right: '4%',
                            bottom: '3%',
                            containLabel: true
                        },
                        // 下载图标png格式
                        toolbox: {
                            feature: {
                                saveAsImage: {}
                            }
                        },
                        xAxis: {
                            type: 'category',
                            boundaryGap: false,
                            data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
                        },
                        yAxis: {
                            type: 'value',
                        },
                        series: [{
                            name: '邮件营销',
                            type: 'line',
                            stack: '总量',
                            data: [120, 132, 101, 134, 90, 230, 210]
                        }, {
                            name: '联盟广告',
                            type: 'line',
                            stack: '总量',
                            data: [220, 182, 191, 234, 290, 330, 310]
                        }, {
                            name: '视频广告',
                            type: 'line',
                            stack: '总量',
                            data: [150, 232, 201, 154, 190, 330, 410]
                        }, {
                            name: '直接访问',
                            type: 'line',
                            stack: '总量',
                            data: [320, 332, 301, 334, 390, 330, 320]
                        }, {
                            name: '搜索引擎',
                            type: 'line',
                            stack: '总量',
                            data: [820, 932, 901, 934, 1290, 1330, 1320]
                        }
                       ]
                    });
                }
            }
        }
    </script>
    
    <style scoped lang="scss">
    
    </style>
    
    

    效果图


    image.png image.png image.png image.png

    相关文章

      网友评论

          本文标题:echarts 图标的小案例

          本文链接:https://www.haomeiwen.com/subject/uhruvltx.html