echarts在Vue中的使用

128 阅读1分钟
<!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>
    <style>

    </style>
    <script src="./echarts.js"></script>
</head>

<body>
    <div id="app">
        <!-- 为 ECharts 准备一个定义了宽高的 DOM -->
        <div id="main" style="width: 600px;height:400px;"></div>
    </div>
    <script src="./vue2.6.14.js"></script>
    <script>
        new Vue({
            el: "#app",
            mounted() {
                let chartsDom = document.getElementById('main');
                /*  基于准备好的dom,初始化echarts实例 */
                let myChart = echarts.init(chartsDom);
                var option = {
                    title: {
                        show:true,
                        text: '电商销量标题',
                        textStyle:{
                            color:"red",
                            fontStyle:"italic",
                            fontWeight:"lighter",
                            fontFamily:"monospace",
                            fontSize:20,
                            lineHeight: 26,
                            width:100,
                            height:30,
                            textBorderWidth:2,
                            textBorderColor:"red",
                            textBorderType:"solid",
                        },
                        left:20,
                        top:10,
                        borderColor:"red",
                        borderWidth:2,
                        borderRadius: [5, 5, 0, 0]
                    },
                    tooltip: {},
                    legend: {
                        data: ['销量']
                    },
                    xAxis: {
                        show:true,
                        data: ['衬衫', '羊毛衫', '雪纺衫']
                    },
                    yAxis: {},
                    series: [
                        {
                            name: '销量',
                            type: 'bar',
                            /* data: [5, 20, 36, 10, 10, 20], */
                            /* itemStyle:{
                                color:"green"
                            }, */
                            data:[{
                                name:"小黄",
                                value:20,
                                itemStyle:{
                                    color:"yellow"
                                } 
                            },{
                                name:"小绿",
                                value:40,
                                itemStyle:{
                                    color:"green"
                                } 
                            },{
                                name:"小红",
                                value:60,
                                itemStyle:{
                                    color:"red"
                                } 
                            }]
                        }
                    ]
                };

                // 使用刚指定的配置项和数据显示图表。
                myChart.setOption(option);
            }
        })
    </script>

</body>

</html>