Echarts

【vue学习】vue里使用echarts

2020-02-06  本文已影响0人  前端菜篮子

官网地址
echarts.apache.org
echartsjs.com



一、安装echarts
npm install echarts --save

二、直接上Demo

<template>
    <div>
        <!-- div的长宽要有 -->
        <div id="myChart" style="width:500px;height:500px;"></div>
    </div>
</template>

<script>
import echarts from 'echarts'
//echart对应的主题
import 'echarts/theme/macarons.js'
export default {
    name: 'hello',
    data () {
        return {
            
        }
    },
    
    methods: {
        drawLine(){
            // 基于准备好的dom,初始化echarts实例
            let myChart = echarts.init(
                document.getElementById('myChart'), 
                'macarons'
            )
            // 绘制图表
            myChart.setOption({
                title: { text: '在Vue中使用echarts' },
                tooltip: {},
                xAxis: {
                    type: 'category',
                    data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
                },
                yAxis: {
                    type: 'value'
                },
                series: [{
                    data: [820, 932, 901, 934, 1290, 1330, 1320],
                    type: 'line'
                }]
            });
        }
    },
    mounted(){
        this.$nextTick( () => {
            this.drawLine();
        })
        
    },
}
</script>



三、几点说明



四、具体每种图表怎么配置参考官方实例即可:点击即可查看相关代码

五、自定义构建 ECharts

一般来说,可以直接从 CDN 中获取构建后的 echarts,也可以从 GitHub 中的 echarts/dist 文件夹中获取构建好的 echarts,这都可以直接在浏览器端项目中使用。这些构建好的 echarts 提供了下面这几种定制:

我们也可以自己构建 echarts,能够仅仅包括自己所需要的图表和组件。可以用这几种方式自定义构建:

上一篇 下一篇

猜你喜欢

热点阅读