微信小程序中-折线图

echarts配置项太多了,还是一点点积累吧~~~~~

当然前提条件还是得老老实实看echarts官方文档 :https://echarts.baidu.com/

今天主要就介绍下我在工作中通过echarts实现的微信小程序的折线图

Demo地址:https://gitee.com/v-Xie/echartsDemo.git

效果嘛如下:

通过此图分析得出需要实现以下几点:(主要配置代码请看后面部分)

1.标题(折线图)-title

  需:颜色,文本,位置

2.图例(财运,感情,事业)-legend

  需:图例颜色,图标形状,图标文本,各图标间隔

3.横纵坐标

  需: 》》横坐标-xAxis

          刻度【周一,周二...周日】,-axisLabel

       分割线 -splitLine

》》纵坐标-yAxis:

          刻度【大吉,...凶】,-axisLabel

       分割线 -splitLine

4.数据项-series

开发吧:

首先下载echarts

进行中:

目录

line/index.wxml

<!--index.wxml-->

<view class="container">

<view class=‘echart_wrap‘>

<ec-canvas id="mychart" canvas-id="mychart-line" ec="{{ ec }}"></ec-canvas>

</view>

</view>

line/index.json

{

"usingComponents": {

"ec-canvas": "../../ec-canvas/ec-canvas"

}

}

line/index.js中

// 引入echarts.js

import * as echarts from ‘../../ec-canvas/echarts‘;

var Chart=null;

const app = getApp();

Page({

data: {

ec: {

onInit: function (canvas, width, height) {

chart = echarts.init(canvas, null, {

width: width,

height: height

});

canvas.setChart(chart);

return chart;

},

lazyLoad: true // 延迟加载

},

},

onLoad: function (options) {

this.echartsComponnet = this.selectComponent(‘#mychart‘);

//如果是第一次绘制

if (!Chart) {

this.init_echarts(); //初始化图表

} else {

this.setOption(Chart); //更新数据

}

},

onReady() {

},

//初始化图表

init_echarts: function () {

this.echartsComponnet.init((canvas, width, height) => {

// 初始化图表

const Chart = echarts.init(canvas, null, {

width: width,

height: height

});

this.setOption(Chart)

// 注意这里一定要返回 chart 实例,否则会影响事件处理等

return Chart;

});

},

setOption: function (Chart) {

Chart.clear(); // 清除

Chart.setOption(this.getOption()); //获取新数据

},

// 图表配置项

getOption() {

var self = this;

var option = {

title: {//标题

text: ‘折线图‘,

left: ‘center‘

},

renderAsImage: true, //支持渲染为图片模式

color: ["#FFC34F", "#FF6D60", "#44B2FB"],//图例图标颜色

legend: {

show: true,

itemGap: 25,//每个图例间的间隔

top: 30,

x: 30,//水平安放位置,离容器左侧的距离 ‘left‘

z: 100,

textStyle: {

color: ‘#383838‘

},

data: [//图例具体内容

{

name: ‘财运‘,//图例名字

textStyle: {//图例文本样式

fontSize: 13,

color: ‘#383838‘

},

icon: ‘roundRect‘//图例项的 icon,可以是图片

},

{

name: ‘感情‘,

textStyle: {

fontSize: 13,

color: ‘#383838‘

},

icon: ‘roundRect‘

},

{

name: ‘事业‘,

textStyle: {

fontSize: 13,

color: ‘#383838‘

},

icon: ‘roundRect‘

}

]

},

grid: {//网格

left: 30,

top:100,

containLabel: true,//grid 区域是否包含坐标轴的刻度标签

},

xAxis: {//横坐标

type: ‘category‘,

name: ‘日期‘,//横坐标名称

nameTextStyle: {//在name值存在下,设置name的样式

color: ‘red‘,

fontStyle: ‘normal‘

},

nameLocation:‘end‘,

splitLine: {//坐标轴在 grid 区域中的分隔线。

show: true,

lineStyle: {

type: ‘dashed‘

}

},

boundaryGap: false,//1.true 数据点在2个刻度直接 2.fals 数据点在分割线上,即刻度值上

data: [‘周一‘, ‘周二‘, ‘周三‘, ‘周四‘, ‘周五‘, ‘周六‘, ‘周日‘],

axisLabel: {

textStyle: {

fontSize: 13,

color: ‘#5D5D5D‘

}

}

},

yAxis: {//纵坐标

type: ‘value‘,

position:‘left‘,

name: ‘运势‘,//纵坐标名称

nameTextStyle:{//在name值存在下,设置name的样式

color:‘red‘,

fontStyle:‘normal‘

},

splitNumber: 5,//坐标轴的分割段数

splitLine: {//坐标轴在 grid 区域中的分隔线。

show: true,

lineStyle: {

type: ‘dashed‘

}

},

axisLabel: {//坐标轴刻度标签

formatter: function (value) {

var xLable = [];

if (value == 20) {

xLable.push(‘大凶‘);

}

if (value == 40) {

xLable.push(‘凶‘);

}

if (value == 60) {

xLable.push(‘平淡‘);

}

if (value == 80) {

xLable.push(‘小吉‘);

}

if (value == 100) {

xLable.push(‘大吉‘);

}

return xLable

},

textStyle: {

fontSize: 13,

color: ‘#5D5D5D‘,

}

},

min: 0,

max: 100,

},

series: [{

name: ‘财运‘,

type: ‘line‘,

data: [18, 36, 65, 30, 78, 40, 33],

symbol: ‘none‘,

itemStyle: {

normal: {

lineStyle: {

color: ‘#FFC34F‘

}

}

}

}, {

name: ‘感情‘,

type: ‘line‘,

data: [12, 50, 51, 35, 70, 30, 20],

// data: ["80", "20", "50", "70", "80", "60", "70"],

symbol: ‘none‘,

itemStyle: {

normal: {

lineStyle: {

color: ‘#FF6D60‘

}

}

}

}, {

name: ‘事业‘,

type: ‘line‘,

data: [10, 30, 31, 50, 40, 20, 10],

// data: ["50", "30", "40", "70", "90", "30", "20"],

symbol: ‘none‘,

itemStyle: {

normal: {

lineStyle: {

color: ‘#44B2FB‘

}

}

}

}],

}

return option;

},

});

      

原文地址:https://www.cnblogs.com/lingXie/p/10620411.html

时间: 2024-08-16 18:34:16

微信小程序中-折线图的相关文章

如何在微信小程序中使用字体图标

微信小程序中,在image标签里,可以在src中引用本地文件,但是background设置背景图或者使用字体图标的时候,却不能引用本地文件,只能用url地址的图片或字体,或者使用base64编码后的格式,图片我们可以在线转换,随便搜一下,有很多在线转换工具,但是使用字体图标的时候,怎么转换呢?下面我们记录一下使用图标字体的l两个方法.    方法一:将字体url转换为base64的格式后使用 第一步,下载需要的字体图: 打开阿里巴巴矢量图标库,选择自己需要的图标添加到购物车,然后点击购物车下载代

图解微信小程序---轮播图

图解微信小程序---轮播图 第一步:在页面创建swiper组件 第二步:编写js页面 注意事项:wx:for渲染我们js中的图片数组,item默认写法,获取我们的图片数组中的图片,可通过增加wx:for-item="it"来改变默认的item名 优化 原文地址:https://www.cnblogs.com/cainiao-chuanqi/p/11604314.html

微信小程序中如何上传图片

本篇文章给大家带来的内容是关于微信小程序中如何上传图片(代码示例),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助. 一.wxml文件 <text>上传图片</text> <view> <button bindtap="uploadimg">点击选择上传图</button> </view> <image src='{{source}}' style='width:600rpx; height:6

微信小程序中target与currentTarget

如有错误,请纠出,大家一起进步!!! target在事件流的目标阶段:currentTarget在事件流的捕获,目标及冒泡阶段.但事件流处于目标阶段,target与currentTarget指向一样, 而当处于捕获和冒泡阶段的时候,target指向被单击的对象而currentTarget指向当前事件活动的对象.在微信小程序中也可总结为:target指向发生事件的组件,currentTarget指向绑定事件的组件. 下面请看例子: text.wxml: <view class="view1&

微信小程序中的 hover-class

微信小程序中,可以用 hover-class 属性来指定元素的点击态效果.但是在在使用中要注意,大部分组件是不支持该属性的. 目前支持 hover-class 属性的组件有三个:view.button.navigator. 不支持 hover-class 属性的组件,同时也不支持 hover-stop-propagation.hover-start-time.hover-stay-time 这三个属性. 使用方法: <view hover-class="bg_red">这是

微信小程序中的单位

vw:viewpoint width,视窗宽度,1vw等于视窗宽度的1%. vh:viewpoint height,视窗高度,1vh等于视窗高度的1%. rpx:rpx单位是微信小程序中css的尺寸单位,rpx可以根据屏幕宽度进行自适应.规定屏幕宽为750rpx.如在 iPhone6 上,屏幕宽度为375px,共有750个物理像素,则750rpx = 375px = 750物理像素,1rpx = 0.5px = 1物理像素. 微信小程序也支持rem尺寸单位,rem和rpx的换算关系:rem: 规

微信小程序中获取高度及设备的方法

由于js中可以采用操纵dom的方法来获取页面元素的高度,可是在微信小程序中不能操纵dom,经过查找之后发现仅仅只有以下几个方法可以获取到高度 wx.getSystemInfoSync().windowWidth // 获取当前窗口的宽度 wx.getSystemInfoSync().windowHeight // 获取当前窗口的高度 wx.getSystemInfoSync().model // 获取当前采用的设备 wx.getSystemInfoSync().pixelRatio wx.get

微信小程序中的循环遍历问题

比如:如果在微信小程序中要遍历输出 0-9 的数,我们会使用for循环 for(var i=0;i<10;i++){ console.log(i); } 确实结果也是这样: 但是,如果我在循环时同时调用wx的api接口10次,那么输出的结果就会不同(这是产生了闭关的效应) eg:每次调用一次wx.showToast()接口,并在成功时输出循环的值. for(var i=0;i<10;i++){ wx.showToast({ title: 'haha', success:function(){

微信小程序中使用ECharts 异步加载数据 实现图表

<!--pages/bar/index.wxml--> <view class="container"> <ec-canvas id="mychart-dom-bar" canvas-id="mychart-bar" ec="{{ ec }}"></ec-canvas> </view> import * as echarts from '../../ec-canvas