vue中使用vue-echarts

一、先说在原生里怎么使用echarts

<!-- 1.引入echarts文件 -->

  <script src="echarts.min.js"></script>

<!-- 准备容器 -->

  <div style="width: 600px;height:400px;" id="main"></div>

//基于dom,初始化echarts实例

  var myChart = echarts.init(document.getElementById(‘main‘))

//制定图表的配置项和数据

  var option = { }

//使用配置项显示图表

  myChart.setOption(option)

二、在vue中使用vue-echarts

// 引入vue-echarts

  import ECharts from ‘vue-echarts/components/Echarts.vue‘

  import ‘echarts/lib/chart/line‘

  import ‘echarts/lib/component/tooltip‘

  Vue.component(‘chart‘, ECharts)

//在build/webpack.base.conf.js中修改成如下东西 {

        test: /\.js$/,
        loader: ‘babel-loader‘,
+       include: [
+         resolve(‘src‘),
+         resolve(‘test‘),
+         resolve(‘node_modules/vue-echarts‘),
+         resolve(‘node_modules/resize-detector‘)
+       ]
 }//在.vue文件中使用

  <div class="left-bottom">

    <div class="title">系统访问量</div>

    <chart style="width: 100%;height: 13rem;position: absolute;top: -2%;" :options="line"></chart>

  </div>

  //配置

  line: {

legend: { // 图例组件颜色配置

data: [

{name: ‘一二三四五六 ‘, icon: ‘circle‘, textStyle: {color: ‘#fff‘}},

{name: ‘一二三四五六  ‘, icon: ‘circle‘, textStyle: {color: ‘#fff‘}},

{name: ‘一二三四五六   ‘, icon: ‘circle‘, textStyle: {color: ‘#fff‘}},

{name: ‘一二三四五六    ‘, icon: ‘circle‘, textStyle: {color: ‘#fff‘}}

]

},

grid: { // 网格

left: ‘-2.3%‘,

right: ‘1.6%‘,

bottom: ‘10%‘,

containLabel: true

},

toolbox: {

feature: {

saveAsImage: {}

}

},

xAxis: {

splitLine: { // 保留网格线

show: true,

lineStyle: {

color: ‘#666‘

}

},

splitArea: { // 去除网格区域

show: false,

lineStyle: {

color: ‘#666‘

}

},

type: ‘category‘,

boundaryGap: false,

axisLine: { // 坐标轴

lineStyle: {

color: ‘#ccc‘

}

},

axisTick: { // 坐标轴刻度设置

inside: true,

interval: 0

},

axisLabel: {

interval: 0,

fontSize: 8

},

data: [‘12:00‘, ‘13:00‘, ‘14:00‘, ‘15:00‘, ‘16:00‘, ‘17:00‘, ‘18:00‘, ‘19:00‘,  ‘20:00‘, ‘21:00‘, ‘22:00‘, ‘23:00‘, ‘24:00‘, ‘01:00‘, ‘02:00‘, ‘03:00‘, ‘04:00‘, ‘05:00‘, ‘‘]

},

yAxis: {

min: 1000,

splitLine: { // 保留网格线

show: true,

lineStyle: {

color: ‘#666‘

}

},

splitArea: { // 去除网格区域

show: false,

lineStyle: {

color: ‘#666‘

}

},

type: ‘value‘,

axisLabel: {

interval: ‘0‘,

fontSize: 8.5

},

axisLine: {

lineStyle: {

color: ‘#ccc‘

}

},

axisTick: {

inside: true

},

data: [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000]

},

series: [

{

name: ‘一二三四五六 ‘,

type: ‘line‘,

stack: ‘总量‘,

symbol: ‘circle‘,

symbolSize: 7,

itemStyle: {

normal: {

color: ‘#00ff7e‘,

lineStyle: {

color: ‘#00ff7e‘

}

}

},

data: [1700, 1720, 1010, 1340, 900, 2300, 2100, 1500]

},

{

name: ‘一二三四五六  ‘,

type: ‘line‘,

stack: ‘总量‘,

symbol: ‘circle‘,

symbolSize: 7,

itemStyle: {

normal: {

color: ‘#0060ff‘,

lineStyle: {

color: ‘#0060ff‘

}

}

},

data: [1200, 1820, 1910, 2304, 2090, 3040, 3010, 3000]

},

{

name: ‘一二三四五六   ‘,

type: ‘line‘,

stack: ‘总量‘,

symbol: ‘circle‘,

symbolSize: 7,

itemStyle: {

normal: {

color: ‘#00ccff‘,

lineStyle: {

color: ‘#00ccff‘

}

}

},

data: [1500, 2320, 2010, 1054, 1900, 3300, 3100, 3500]

},

{

name: ‘一二三四五六    ‘,

type: ‘line‘,

stack: ‘总量‘,

symbol: ‘circle‘,

symbolSize: 7,

itemStyle: {

normal: {

color: ‘#ffae00‘,

lineStyle: {

color: ‘#ffae00‘

}

}

},

data: [1200, 3320, 301, 3304, 3900, 330, 3200, 3050]

}

]

}

line2: {

legend: { // 图例组件颜色配置

data: [

{name: ‘一二三四五六 ‘, icon: ‘circle‘, textStyle: {color: ‘#fff‘}},

{name: ‘一二三四五六 ‘, icon: ‘circle‘, textStyle: {color: ‘#fff‘}},

{name: ‘一二三四五六 ‘, icon: ‘circle‘, textStyle: {color: ‘#fff‘}},

{name: ‘一二三四五六 ‘, icon: ‘circle‘, textStyle: {color: ‘#fff‘}}

]

},

grid: { // 网格

left: ‘-2.3%‘,

right: ‘1.6%‘,

bottom: ‘10%‘,

containLabel: true

},

toolbox: {

feature: {

saveAsImage: {}

}

},

xAxis: {

splitLine: { // 保留网格线

show: true,

lineStyle: {

color: ‘#666‘

}

},

splitArea: { // 去除网格区域

show: false,

lineStyle: {

color: ‘#666‘

}

},

type: ‘category‘,

boundaryGap: false,

axisLine: { // 坐标轴

lineStyle: {

color: ‘#ccc‘

}

},

axisTick: { // 坐标轴刻度设置

inside: true,

interval: 0

},

axisLabel: {

interval: 0,

fontSize: 8

},

data: [‘12:00‘, ‘13:00‘, ‘14:00‘, ‘15:00‘, ‘16:00‘, ‘17:00‘, ‘18:00‘, ‘19:00‘, ‘20:00‘, ‘21:00‘, ‘22:00‘, ‘23:00‘, ‘24:00‘, ‘01:00‘, ‘02:00‘, ‘03:00‘, ‘04:00‘, ‘05:00‘, ‘‘]

},

yAxis: {

min: 1000,

splitLine: { // 保留网格线

show: true,

lineStyle: {

color: ‘#666‘

}

},

splitArea: { // 去除网格区域

show: false,

lineStyle: {

color: ‘#666‘

}

},

type: ‘value‘,

axisLabel: {

interval: ‘0‘,

fontSize: 8.5

},

axisLine: {

lineStyle: {

color: ‘#ccc‘

}

},

axisTick: {

inside: true

},

data: [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000]

},

series: [

{

name: ‘一二三四五六 ‘,

type: ‘line‘,

stack: ‘总量‘,

symbol: ‘none‘,

itemStyle: {

normal: {

color: ‘rgba(0, 254, 116, 0.3)‘,

lineStyle: {

color: ‘#00ff7e‘

}

}

},

areaStyle: {normal: {}},

data: [1700, 1720, 1010, 1340, 900, 2300, 2100, 1500, 1100]

},

{

name: ‘一二三四五六 ‘,

type: ‘line‘,

stack: ‘总量‘,

symbol: ‘none‘,

itemStyle: {

normal: {

color: ‘rgba(0, 109, 255, 0.3)‘,

lineStyle: {

color: ‘#0060ff‘

}

}

},

areaStyle: {normal: {}},

data: [1200, 1820, 1910, 2304, 2090, 3040, 3010, 3000, 1500]

},

{

name: ‘一二三四五六 ‘,

type: ‘line‘,

stack: ‘总量‘,

symbol: ‘none‘,

itemStyle: {

normal: {

color: ‘rgba(0, 204, 255, 0.3)‘,

lineStyle: {

color: ‘#00ccff‘

}

}

},

areaStyle: {normal: {}},

data: [1500, 2320, 2010, 1054, 1900, 3300, 3100, 3500, 2000]

},

{

name: ‘一二三四五六 ‘,

type: ‘line‘,

stack: ‘总量‘,

symbol: ‘none‘,

itemStyle: {

normal: {

color: ‘rgba(255, 174, 0, 0.3)‘,

lineStyle: {

color: ‘#ffae00‘

}

}

},

areaStyle: {normal: {}},

data: [1200, 3320, 1301, 2304, 2900, 3300, 2200, 1050, 2500]

}

]

}

原文地址:https://www.cnblogs.com/surui/p/8484447.html

时间: 2024-07-30 09:06:42

vue中使用vue-echarts的相关文章

vue中如何使用echarts

在vue中使用echarts主要是注意如何与vue生命周期相结合,从而做到数据驱动视图刷新 主要是以下几步: echarts的option设置在data(){}中 在mounted(){}生命周期去初始化数据,初始化echarts 在updated(){}生命周期中去setOption(option)渲染echarts. 模板vue文件如下: <template> <div id="myChart" ref="myChart"></di

在vue中使用的Echarts的步骤

1.首先在项目中安装Echarts npm install echarts -g --save //安装 2.在项目中引入Echarts(在main.js中引入) import echarts from 'echarts' //引入Echarts, Vue.prototype.$echarts = echarts //定义为全局变量 3.使用并绘制简单表格(承载画布的div必须要定义大小width.height) <template> <!-- ref="myechart&qu

vue中如何使用echarts,使用axios获取数据

1==>首先准备一个容器 <div id="echartContainer" style="width:400px; height:400px"></div> <!--创建一个echarts的容器--> 2==>在当前的页面中使用axios  和   引入放在本地在static文件中的静态文件op.js    引入echarts import axios from 'axios'; import {option} fr

Vue中组件(.vue文件)

Vue组件 组件的构成 一个.vue文件就是一个组件 组件都是由三部分组成:html结构(html结构都是在template标签中).js逻辑.css样式 1)template只能解析一个根标签 2)js逻辑都是在script标签中,必须设置导出,export default {...} 3)css样式都是在style标签中,必须设置scoped属性,是样式组件化 <template> <div class="first-cp"> <h1>第一个组件

Vue系列——在vue项目中使用echarts

安装echarts依赖 npm install echarts -S 创建图表 全局引入 main.js // 引入echarts import echarts from 'echarts' Vue.prototype.$echarts = echarts Hello.vue <div id="myChart" :style="{width: '300px', height: '300px'}"></div> export default {

项目vue中使用echarts步骤

1.在组件中创建该模块 <template> <div id = "testChart"></div> </template> 2.导入echarts 前提是:已经在项目中配置过echarts 在<script></script>中导入echarts <script> import {echartInit} from "../../../utils/echartUtils" <

VUE中使用Echarts绘制柱状图

在main.js中引入echarts import echarts from 'echarts' Vue.prototype.$echarts = echarts 在相应的vue中导入echarts import echarts from 'echarts'; 实现柱状图显示 <div style="width: 100%;height: 50%;border:1px solid rgb(180,180,180);top: 0px" id="echartss"

Vue中echarts的基本用法

前言:同大多数的前端框架一样,先读官网的使用方法.学会基本使用后,在实例中找到自己想要demo.拿过来改一改,一个echarts图表就形成,毕竟人家做就是为了方便使用. 我是在vue中下面直接使用的echarts.下面按步骤讲解. 第一步:安装echarts依赖包,然后引入,注意最好在当前使用的组件中引入,而不需要在main.js中注册. //1.首先引入 import echarts from "echarts"; 第二步:在页面中创建一个盒子,用来装载图表 <!-- 2.为e

vue中使用 echarts3.0 或 echarts2.0 (模拟迁徙图,折线图)

一.echarts3.0(官网: http://echarts.baidu.com/) 首先通过npm安装echarts依赖,安装的为3.0版本 npm install echarts -s 也可以使用淘宝镜像 npm install -g cnpm --registry=https://registry.npm.taobao.org cnpm install echarts -s 引入的方式有两种: 1.main.js中全局引入 import echarts from 'echarts' Vu

vue中监听window.resize的变化

我只想说每个人遇到的bug真的不能一概而论,解决办法也会有不同.在vue中使用echarts的时候,会想要实现window.resize窗体变化大小的时候让图形大小跟着变化.实现的过程中各种bug,也真的让人有种想要发狂的感觉.但是还好,最后在不断的查资料和尝试当中.实现了想要的效果,仅供参考: 首先我这里实现的效果是切换echart图形,然后在window.resize过程中想要实现自适应窗口大小的变化. 这里的两个button分别是控制两个路由切换,也就是两个echart图形(柱状图和饼图)