| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- // pages/number/number.js
- import * as echarts from '../../ec-canvas/echarts';
- const app = getApp()
- var host = app.globalData.host;
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- info:{},
- day:'',
- ec: {
- // onInit: initChart
- lazyLoad: true
- },
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- var y = new Date().getFullYear(), m = (new Date().getMonth() + 1), d = new Date().getDate();
- m = m > 9 ? m : '0' + m;
- d = d > 9 ? d : '0' + d;
- this.setData({
- day: y + '-' + m + '-' + d
- })
- options.id=2;
- wx.showNavigationBarLoading()
- wx.request({
- url: host + '/api/casci/detail',
- method: 'GET',
- data: {
- id: options.id
- },
- success: res => {
- wx.hideNavigationBarLoading()
- if (res.data.code == 0) {
- this.setData({
- info:res.data.data
- })
-
- var records = res.data.data.days7_casci, xdata = [], ydata = [];
- if (records.length <= 0) {
- return;
- }
- for (let i = 0; i < records.length; i++) {
- xdata.push(records[i].name)
- ydata.push(records[i].value)
- xdata.push(records[i].name)
- ydata.push(2500)
- xdata.push(records[i].name)
- ydata.push(1800)
- }
- // xdata = xdata.reverse()
- // ydata = ydata.reverse()
- this.oneComponent = this.selectComponent('#mychart');
- this.init_one(xdata, ydata)
- }
- }
- })
- },
- init_one: function (xdata, ydata) { //初始化第一个图表
-
- this.oneComponent.init((canvas, width, height, dpr) => {
- const chart = echarts.init(canvas, null, {
- width: width,
- height: height,
- devicePixelRatio: dpr
- });
- setOption(chart, xdata, ydata)
- this.chart = chart;
- return chart;
- });
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
- function setOption(chart, xdata, ydata) {
- var option = {
- legend: {
- show: false
- },
- backgroundColor:'#F1F4F6',
- grid: {
- x: 50,
- y: 40,
- x2: 10,
- y2: 35
- },
- tooltip: {
- show: true,
- trigger: 'axis',
- formatter: '{b0}: {c0}'
- },
- xAxis: {
- type: 'category',
- data: xdata,
- axisLabel: {
- interval: 0,
- // rotate: 40,
- color: '#999999'
- }
- },
- yAxis: {
- axisLine: {
- show: true
- },
- type: 'value',
- name: '',
- axisLabel: {
- formatter: function (value, index) {//隐藏 0
- let texts = [];
- texts.push(value)
- return texts;
- },
- show: true
- },
- },
- series: [{
- name: 'A',
- type: 'line',
- smooth: true,
- symbolSize: 8,
- lineStyle: {
- color: '#FF9F2E'
- // color: new echarts.graphic.LinearGradient(1, 0, 0, 0, [{
- // offset: 0,
- // color: '#FF2D68'
- // }, {
- // offset: 1,
- // color: '#4C4BFF'
- // }]),
- },
- areaStyle: {
- color: {
- //线性渐变
- type: 'linear',
- x:0,
- y:0,
- x2:0,
- y2:1,
- colorStops: [{
- offset: 0, color: 'rgba(255, 159, 46, .5)', // 0% 处的颜色
- }, {
- offset: 1, color: 'rgba(255, 159, 46, .2)', // 100% 处的颜色
- }],
- global: false, // 缺省为 false
- },
- },
- itemStyle: {
- borderWidth: 5,
- borderColor: '#FFAD52',
- color: '#FFAD52'
- },
- data: ydata
- }]
- };
- chart.setOption(option)
- }
|