vue使用echarts实现折线图

本文实例为大家分享了vue使用echarts实现折线图的具体代码,供大家参考,具体内容如下

效果图:

代码:

<template>
            <div class="proCharts" ref='charts'>
            </div>
</template>

<script>
import echarts from 'echarts'   //npm install echarts@4.9.0
export default {
    data () {
        return {
            option:{
                    color:['rgb(8,252,7)','rgb(255,168,0)',],
                    title: {
                        text: ''
                    },
                    tooltip: { //提示框
                        trigger: 'axis',
                    },
                    legend: {//图例的类型
                        icon:'roundRect',//图例icon图标
                        data: [
                            {
                                name:"上年",
                                textStyle: {
                                    color: '#fff'
                                }
                                
                            },{
                                name:"本年",
                                textStyle: {
                                    color: '#fff'
                                }
                            },
                        ],
                        
                    },
                    grid: {
                        left: '3%',
                        right: '4%',
                        bottom: '3%',
                        top:'17%',
                        containLabel: true //grid区域是否包含坐标轴的刻度标签
                    },
                    xAxis: {
                        type: 'category', //坐标轴类型。
                        boundaryGap: false, //坐标轴两边留白策略
                        data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月','8月','9月','10月','11月','12月'],
                        axisLabel: {//坐标轴刻度标签的相关设置
                            interval:0,
                            textStyle: {
                            color: '#fff',
                            fontSize :10
                            },
                        },
                        axisLine:{//坐标轴轴线相关设置
                            show :true,
                            lineStyle:{
                                color:'rgb(2,121,253)'
                            }
                        },
                        axisTick:{ //坐标轴刻度相关设置。
                            show :false,
                        }
                    },
                    yAxis: {
                        type: 'value',
                        axisLabel: { //x轴的坐标文字
                            show: true,
                            textStyle: {
                                color: '#fff' //文字的颜色
                            },
                            
                        },
                        max:100,//最大值100
                        axisLine:{//坐标轴轴线相关设置
                            show :true,
                            lineStyle:{
                                color:'rgb(2,121,253)'
                            }
                        },
                        axisTick:{ //坐标轴刻度相关设置。
                            show :false,
                        },
                        splitLine:{  //坐标在grid区域的分割线
                          lineStyle: { //设置分割线的样式(图表横线颜色)
                                color: ['#153a8a']
                            }
                        }
                    },
                    series: [
                        {
                            name: '上年',
                            type: 'line',
                            data: [10,20,30,50,50,10,50,60,10,50,10,30],
                            lineStyle:{
                                color:'rgb(8,252,7)'  //线的颜色
                            }
                        },
                        {
                            name: '本年',
                            type: 'line',
                            data: [20,20,30,50,50,10,50,20,30,50,50,30],
                            lineStyle:{
                                color:'rgb(255,168,0)' //线的颜色
                            }
                        }
                    ]
                }
        }
    },
    created () {
        
    },
    mounted () {
        this.mycharts()
    },
    methods: {
        mycharts(){
            let myChart =echarts.init(this.$refs.charts,"macarons");
            myChart.setOption(this.option)
            //图表自适应
            window.addEventListener("resize",function(){
                myChart.resize()  // myChart 是实例对象
            })
        }
    }
}
</script>

<style scoped>
.proCharts{
    width: 100%;
    height: 400px;
    background: rgb(14, 51, 129);
}
</style>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。

(0)

相关推荐

  • vue实现折线图 可按时间查询

    本文实例为大家分享了vue实现可按时间查询的折线图的具体代码,供大家参考,具体内容如下 1.vue前端 //查询条件 <template> <el-date-picker v-model="listQuery.toptime" :picker-options="pickerOptions" style="width: 380px" type="daterange" clearable range-separa

  • 在vue中使用echarts(折线图的demo,markline用法)

    公司最近在用vue开发项目,项目接近尾声了,趁休息时间写点demo-- vue引入echarts(折线图的demo) 主要是解决引入echarts,markline的使用(基准线) 这是demo的效果图: vue脚手架不多赘述 1.安装依赖 cnpm install echarts -S 2.在main.js中引入echarts import echarts from 'echarts' 3.在main.js中安装 Vue.prototype.echarts = echarts; 一般来说能正常

  • vue+echarts实现动态折线图的方法与注意

    之前公司有个绘制实时盈利率折线图的需求,实现的还不错,今天来分享下vue+echarts实现动态折线图的方法. 实现代码 <template> <div id="myChart"></div> </template> <script> import echarts from 'echarts' export default { name: 'DynamicLineChart', data () { return { // 实时

  • vue+echarts实现可拖动节点的折线图(支持拖动方向和上下限的设置)

    本篇文档主要是利用echarts实现可拖动节点的折线图,在echarts中找到了一个demo,传送门:https://echarts.baidu.com/examples/editor.html?c=line-draggable,但是不是用vue写的,并且在改写为vue组件的过程中遇到了很多问题,在百度过程中发现并没有相关的文档,所以决定自己开发,并在demo的基础上开发了一些实用的功能,所以把这个过程记录下来.文档中还有很多不够完善的地方,欢迎讨论哈! 需求:制作一个折线图用于显示当前24小时

  • vue使用ECharts实现折线图和饼图

    在开发后台管理项目时,需要统计后台用户数据,以折线图和饼图的形式显示,这边采用apache-echarts来实现需求. 1.安装echarts和引入 npm install echarts --save import * as echarts from 'echarts'; 2.使用echarts实现pie图 <template> <div id="chartPie" class="pie-wrap"></div> </te

  • 基于mpvue小程序使用echarts画折线图的方法示例

    第一次使用mpvue框架来写小程序,项目开发直接搬用mpvue-shop(一个仿网易严选的小程序开发项目),项目结构清楚,实现了大部分功能,对于初次使用mpvue的小伙伴们来说,是一个很好的选择. 关于组件的选择: 1.echarts-for-weixin,官方echarts的小程序版本.使用参考:echarts-for-weixin介绍,如果你是原生开发小程序版本,这个组件非常适合你,开发过程中可使用echarts官方提供的所有配置和Api,但并不适合mpvue项目. 2.wx-charts,

  • vue使用echarts实现折线图

    本文实例为大家分享了vue使用echarts实现折线图的具体代码,供大家参考,具体内容如下 效果图: 代码: <template>             <div class="proCharts" ref='charts'>             </div> </template> <script> import echarts from 'echarts'   //npm install echarts@4.9.0

  • Vue导入Echarts实现折线散点图

    本文实例为大家分享了Vue导入Echarts实现折线散点图的具体代码,供大家参考,具体内容如下 效果图: 一.vue-cli中导入echarts 通过命令:npm install echarts --save进行下载到项目中,然后在项目中的main.js中进行导入且保存在vue的原型上. main.js代码如下: import Vue from 'vue' import App from './App.vue' const echarts = require("echarts") Vu

  • vue+echart实现圆滑折线图

    本文实例为大家分享了vue+echart实现圆滑折线图的具体代码,供大家参考,具体内容如下 效果图: 安装依赖: npm install echarts --save     import echarts from "echarts"; 完整代码: <template>   <div>     <div id="demo"></div>   </div> </template> <scri

  • jQuery插件echarts设置折线图中折线线条颜色和折线点颜色的方法

    本文实例讲述了jQuery插件echarts设置折线图中折线线条颜色和折线点颜色的方法.分享给大家供大家参考,具体如下: 1.问题背景 设计一条折线图,但是图形中不用插件自带的颜色,需要自定义线条和折点的颜色 2.实现源码 (1)图形自分配颜色 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>echarts-设置折线图中折线线条颜色和折线点颜色</t

  • 使用laravel和ECharts实现折线图效果的例子

    1.首先引入echart.js <script type="text/javascript" src="{{ asset('/public/js/echarts.js') }}"></script> 2.html页面,要有一个布局容器,用来显示图像,一定要设置宽和高 <div class="contain" style="width: 84%;" id="contain">

  • echarts实现折线图的拖拽效果

    使用echarts实现折线图的拖拽,供大家参考,具体内容如下 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="./echarts.js"></script> </head> <body> <div id="main" style="width: 600p

随机推荐