小程序echarts

一、引入ec-canvas文件
https://github.com/ecomfe/echarts-for-weixin
“ec-canvas”
二、配置json

{
  "usingComponents":{
    "ec-canvas":"../../ec-canvas/ec-canvas"
  }
}

三、书写结构

<!--logs.wxml-->
<view class="container log-list">
  <ec-canvas id="mychart-dom-line" canvas-id="mychart-line" ec="{{ec}}"></ec-canvas>
</view>

四、js文件

//logs.js
const util = require('../../utils/util.js')
import * as echarts from '../../ec-canvas/echarts'
const app = getApp()
function initChart(canvas,width,height){
  const chart = echarts.init(canvas,null,{
    width:width,
    height:height
  })
  canvas.setChart(chart)
  var option = {
    color:["#37A2DA","#67E0E3","#9FE6B8"],
    legend:{
      data:["A","B","C"],
      top:20,
      left:"center",
      z:100
    },
    grid:{
      left:"3%",
      right:"4%",
      bottom:"3%",
      containLabel:true
    },
    xAxis:{
      type:"category",
      boundaryGap:false,
      data:["周一","周二","周三","周四","周五","周六","周日"]

    },
    yAxis:{
      x:"center",
      type:"value",
      splitLine:{
        lineStyle:{
          type:"solid"
        }
      }
    },
    series:[{
      name:'A',
      type:"line",
      smooth:true,
      data:[18,36,65,30,78,40,33]
    }, {
        name: 'B',
        type: "line",
        smooth: true,
        data: [12, 50, 51, 35, 70, 40, 33]
      }
      , {
        name: 'C',
        type: "line",
        smooth: true,
        data: [10, 30, 31, 50, 40, 20, 33]
      }]
  }
  chart.setOption(option)
  return chart
}
Page({
  onShareAppMessage:function(res){
    return{
      title:"Echarts",
      path:"/pages/index/index",
      success:function(){},
      fail:function(){}
    }
  },
  data: {
    ec:{
      onInit:initChart
    },
    logs: []
  },
  onReady(){},
  onLoad: function () {
    this.setData({
      logs: (wx.getStorageSync('logs') || []).map(log => {
        return util.formatTime(new Date(log))
      })
    })
  }
})
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • "use strict";function _classCallCheck(e,t){if(!(e instanc...
    久些阅读 2,068评论 0 2
  • mean to add the formatted="false" attribute?.[ 46% 47325/...
    ProZoom阅读 2,736评论 0 3
  • 很庆幸这次的决定是正确的,第一次带上孩子踏出远游的脚步。行程是五月初定下来的,和闺蜜们一起,带着孩子在暑假的前一星...
    xyz心若幽兰阅读 6,943评论 2 6
  • 在父母跟前的日子,闲淡懒散。 烟台老家的房子两个床一个炕,我一天的主要任务就是吃饱饭后抱本书或者手机,躲着太阳,从...
    牟牟的阅读 577评论 4 7
  • 在诗前我先得庆祝一下,应为我的简书创作已经到了第十篇了,感谢大家这些天来的支持与阅读。 连绵的青山, 芬芳的花朵,...
    眼镜先森阅读 256评论 1 6