zoukankan      html  css  js  c++  java
  • vue 使用echarts 一个小案例 宽度自适应

     

    以组件的形式引入项目中

    组件:

    <template>
        <div>
            <div :class="className" :id="id" :style="{height:height,width}"></div>
        </div>
    </template>
    
    <script>
    // 引入基本模板
    let echarts = require("echarts/lib/echarts");
    // 引入柱状图组件
    require("echarts/lib/chart/bar");
    // 引入提示框和title组件
    require("echarts/lib/component/tooltip");
    //分类标题
    require("echarts/lib/component/legend");
    
    export default {
        props:['sourse'],
        data() {
            return {
                className: "echarts",
                id: "main",
                height: "360px",
                 "100%",
                option: {
                    legend: {},
                    // color: ["#3C90F7", "#E05667", "#1AB394", "#F4CD49"],
                    color: ["green", "yellow", "red", "#ab0"],
                    dataset: {
                        source:this.sourse,
                    },
                    xAxis: {
                        type: "category",
                        axisTick: {
                            show: false,
                        },
                    },
                    tooltip:{
                        show:true
                    },
                    yAxis: {},
                    series: [
                        {
                            type: "bar",
                            seriesLayoutBy: "row",
                        },
                        {
                            type: "bar",
                            seriesLayoutBy: "row",
                        },
                        {
                            type: "bar",
                            seriesLayoutBy: "row",
                        },
                        {
                            type: "bar",
                            seriesLayoutBy: "row",
                        },
                    ],
                },
            };
        },
        mounted() {
            var myChart = echarts.init(document.getElementById("main"));
            // console.log(myChart);
            this.$nextTick(_=>{
                myChart.setOption(this.option);
            })
            window.addEventListener('resize',this.resize())
        },
        methods:{
      //自适应宽度 resize(){ let that
    = this; let timer = null; return function(){ if(timer){ clearTimeout(timer) } timer=setTimeout(()=>{ var myChart = echarts.init(document.getElementById("main")); myChart.resize(); }) } } } }; </script> <style lang='scss' scoped> </style>

    父组件:

    引用:

    <bar :sourse='sourse'></bar>
    

      数据:

    sourse: [["type", "一组", "二组","三组","四组"],
                           ["月初", 320, 332, 301, 334],
                           ["月末", 220, 182, 191, 234],
                           ["离职", 150, 232, 201, 154],
               ],

      注: 上文echarts 自适应宽度,转载自https://blog.csdn.net/gobacka/article/details/89183993  

  • 相关阅读:
    跳出iframe
    leetcode 225. Implement Stack using Queues
    leetcode 206. Reverse Linked List
    leetcode 205. Isomorphic Strings
    leetcode 203. Remove Linked List Elements
    leetcode 198. House Robber
    leetcode 190. Reverse Bits
    leetcode leetcode 783. Minimum Distance Between BST Nodes
    leetcode 202. Happy Number
    leetcode 389. Find the Difference
  • 原文地址:https://www.cnblogs.com/fuyuanling/p/13681493.html
Copyright © 2011-2022 走看看