国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

微信小程序使用Echart實現(xiàn)折線圖案例

這篇具有很好參考價值的文章主要介紹了微信小程序使用Echart實現(xiàn)折線圖案例。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

?一、實現(xiàn)效果

微信小程序使用Echart實現(xiàn)折線圖案例

二、echart引入?yún)⒖剂硪晃徊┲鞑┛?/p>

微信小程序引入echarts圖表(保姆式)_啊翔呀的博客-CSDN博客_微信小程序引入echarts

總結(jié)來就是以下幾步

?1.首先,下載echarts微信版 地址:GitHub - ecomfe/echarts-for-weixin: Apache ECharts 的微信小程序版本

2.把ec-canvas文件復(fù)制到項目中,由于我項目采用的是分包,故直接復(fù)制到需要使用到echart圖表的包下。

微信小程序使用Echart實現(xiàn)折線圖案例

?3.在app.json文件中加入下代碼

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

4.datacharts.wxml文件

<!-- 頭部標題 -->
<view class="title_search">
  <view class="seeck_md">
    <!-- 返回 -->
    <view class="logout" bindtap="logout">
      <image class="logout_ic" src="/images/add.png">
      </image>
      <text class="logout_txt">返回</text>
    </view>
    <!--消息-->
    <view class="msg_title_center">
      <view class="msg" bindtap="open_msg">
        <text class="msg_txt">個人數(shù)據(jù)</text>
      </view>
    </view>
  </view>
  <view class="logout">
    <image class="logout_ic">
    </image>
    <text class="logout_txt"></text>
  </view>
</view>

<scroll-view class='scbg' scroll-y='true'>
   <!-- 刷新時間  -->
  <view class="refresh">{{titleDate}}</view>
  <view class="chart_module">
    <!-- 大氣壓等選擇 -->
    <view class="blood_class_selet">
      <view bindtap="booldPress" class="{{pressList[0].checked?'bloodPressureActived':'bloodPressure'}}" >氣壓</view>
      <view bindtap="booldTa" class="{{pressList[1].checked?'bloodPressureActived':'bloodPressure'}}">大氣</view>
      <view bindtap="booldO" class="{{pressList[2].checked?'bloodPressureActived':'bloodPressure'}}">
        OX</view>
      <view bindtap="booldHaert" class="{{pressList[3].checked?'bloodPressureActived':'bloodPressure'}}">頻率</view>
      <view bindtap="booldWeight" class="{{pressList[4].checked?'weightActive':'weight'}}">
      重量</view>
    </view>
    <!--圖表數(shù)據(jù)-->
    <view class="echarts">
      <ec-canvas force-use-old-canvas="true" id="my-echarts" canvas-id="echarts" ec="{{ec}}"></ec-canvas>
    </view>
    <!--月、季度、年選擇-->
    <view class="day_select">
      <view class="time_interval">時間跨度</view>
      <view class="bottom_button">
        <view class="{{diseaseList[0].checked?'mouth':'mouthnomal'}}" bindtap="weekSelcet">月</view>
        <view class="{{diseaseList[1].checked?'yearative':'year'}}" bindtap="monthSelect">季</view>
        <view class="{{diseaseList[2].checked?'yearative':'year'}}" bindtap="yearselect">年</view>
      </view>
    </view>
  </view>

  <!-- 歷史數(shù)據(jù) -->
  <view class="history_data">歷史數(shù)據(jù)</view>
  <block wx:for="{{HistoryDataList}}" wx:key="id" wx:for-item="itemName" wx:for-index="id">
    <view class='box'>
      <view class='firstblock'>
        <!-- 日期 -->
        <text class='showdata'>{{itemName.data_times}}</text>
        <view class='tel'>
          <text class='showdataone'>{{itemName.values}}</text>
          <!-- <text class='showdatatwo'>/{{itemName.values}}</text> -->
          <text class='dataunit'>{{itemName.unit}}</text>
        </view>
      </view>
    </view>
  </block>
</scroll-view>

5.datacharts.wxss

page {
  background: #f0f0f0;
  left: 0rpx;
  right: 0rpx;
}

.refresh {
  font-size: 22rpx;
  justify-content: center;
  display: flex;
  align-items: center;
  margin-top: 30rpx;
  margin-bottom: 20rpx;
}

/* 圖表模塊 */
.echarts {
  width: 580rpx;
  height: 400rpx;
  font-size: 24rpx;
  color: #000;
  background-color: white;
  border-radius: 30rpx;
  padding-bottom: 30rpx;
}
#echarts{
  background-color: #0455a7;
}

.chart_module {
  display: flex;
  justify-content: flex-end;
  margin-top: 30rpx;
  align-items: flex-end;
  margin-right: 30rpx;
  flex-direction: row;
}

/* 日期選擇*/
.day_select {
  display: flex;
  position: absolute;
  flex-direction: row;
}

.time_interval {
  font-size: 28rpx;
  height: 56rpx;
  align-items: center;
  display: flex;
  color: #a7a7a7;
  margin-right: 10rpx;
}

/* 大氣模塊選擇*/
.blood_class_selet {
  height: 430rpx;
  width: 80rpx;
  background-color: #d3d3d3;
  color: #000;
  border-radius: 20rpx;
  font-size: 28rpx;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  margin-right: 20rpx;
}

/* 大氣*/
.bloodPressure {
  width: 74rpx;
  height: 64rpx;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  border-radius: 20rpx;
  margin-top: 4rpx;
}

.bloodPressureActived {
  width: 74rpx;
  height: 64rpx;
  background-color: white;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  border-radius: 20rpx;
  margin-top: 4rpx;
}

/* 重量 */
.weightActive {
  width: 74rpx;
  height: 64rpx;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  border-radius: 20rpx;
  margin-bottom: 4rpx;
  background-color: white;
}

.weight {
  width: 74rpx;
  height: 64rpx;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  border-radius: 20rpx;
  margin-bottom: 4rpx;
}
/* 重量 */

/* 時間選擇模塊*/
.bottom_button {
  display: flex;
  flex-direction: row;
  background-color: #d3d3d3;
  width: 280rpx;
  height: 56rpx;
  align-items: center;
  border-radius: 28rpx;
  justify-content: space-between;
  margin-right: 20rpx;
  margin-bottom: 10rpx;
  font-size: 28rpx;
}

.mouth {
  width: 84rpx;
  height: 46rpx;
  background-color: white;
  align-items: center;
  margin-left: 5rpx;
  justify-content: center;
  display: flex;
  border-radius: 24rpx;
}

.mouthnomal {
  width: 84rpx;
  height: 46rpx;
  align-items: center;
  margin-left: 5rpx;
  justify-content: center;
  display: flex;
}

.year {
  width: 84rpx;
  height: 46rpx;
  align-items: center;
  margin-left: 5rpx;
  justify-content: center;
  display: flex;
  border-radius: 24rpx;
  margin-right: 5rpx;
}

.yearative {
  width: 84rpx;
  height: 46rpx;
  background-color: white;
  align-items: center;
  margin-left: 5rpx;
  justify-content: center;
  display: flex;
  border-radius: 24rpx;
  margin-right: 5rpx;
}

/* 圖表模塊 */

/* 歷史記錄 */
.scbg {
  background-color: #f0f0f0;
  width: 100%;
  height: calc(100vh - 200rpx);
  left: 0rpx;
  right: 0rpx;
  top: 0rpx;
  padding-bottom: 30rpx;
}

/* 隱藏滾動條 */
::-webkit-scrollbar {
  width: 0;
  height: 0;
  color: transparent;
}

/* 歷史數(shù)據(jù) */
.history_data {
  margin-top: 40rpx;
  margin-bottom: 30rpx;
  margin-left: 30rpx;
  font-weight: bold;
  color: #444444;
}

/* 歷史數(shù)據(jù)item */
.box {
  background-color: white;
  margin-top: 20rpx;
  border-radius: 20rpx;
  margin-left: 30rpx;
  margin-right: 30rpx;
}

.firstblock {
  height: 150rpx;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-radius: 20rpx;
  flex-direction: row;
  padding-right: 30rpx;
}

.showtime {
  font-size: 24rpx;
  color: #333333;
  font-family: PingFangSC-regular;
}

.showdataone {
  font-size: 32rpx;
  color: #000000;
  font-family: PingFangSC-regular;
  font-weight: bold;
  margin-right: 5rpx;
}

.showdatatwo {
  font-size: 32rpx;
  color: #000000;
  font-weight: bold;
  font-family: PingFangSC-regular;
}

.dataunit {
  font-size: 24rpx;
  color: #363636;
  margin-left: 10rpx;
  margin-right: 10rpx;
  font-family: PingFangSC-regular;
}

.showdata {
  width: 160rpx;
  font-size: 24rpx;
  color: #a7a7a7;
  margin-left: 30rpx;
}
/* 歷史數(shù)據(jù)item */

/* 頭部搜索 */
/* 搜索標題 */
.title_search{
  background: linear-gradient(to right, #0455a7, #62c8ec);
  height: 170rpx;
  width: 100%;
  display: flex;
  flex-direction: row;
  align-items: flex-end;
  justify-content: flex-start;
}
.seeck_md{
  display: flex;
  flex-direction: row;
  width: 100%;
  justify-content: flex-start;
  align-items: flex-end;
}

/* 消息 */
.msg{
  width: 180rpx;
  height: 90rpx; 
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  margin-right: 0rpx;
  margin-left: 30rpx;

}

.msg_title_center{
  width: 100%;
  display: flex;
  flex-direction: row;
  justify-content: center;
}
.msg_txt{
  font-size: 36rpx;
  height: 80rpx;
  width: 160rpx;
  margin-bottom: 20rpx;
  align-items: center;
  color: #fff;
  display: flex;
  justify-content: center;
}

/* 返回 */
.logout{
  width: 100rpx;
  height: 90rpx; 
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  margin-right: 20rpx; 
  margin-left: 30rpx;
}
.logout_ic{
  height: 44rpx;
  width: 48rpx;
  margin-right: 2rpx;
}
.logout_txt{
  font-size: 24rpx;
  height: 40rpx;
  width: 60rpx;
  margin-bottom: 10rpx;
  align-items: flex-start;
  color: #fff;
  display: flex;
  justify-content: flex-start;
}
/* 搜索標題 */
/* 頭部搜索  */

6.datacharts.ts,注意由于我是放在分包里面故在js文件中引入為import?*?as?echarts?from?'../../../../ec-canvas/echarts';

如果放在主包引用則改為

import?*?as?echarts?from?'../../ec-canvas/echarts';文章來源地址http://www.zghlxwxcb.cn/news/detail-437534.html

// 引入echarts.js
import * as echarts from '../../../../ec-canvas/echarts';

let chart = null;

Page({
  data: {
    ec: {
      onInit: initChart
    },
    titleDate: '',
    refreshData: '',
    diseaseList: [//月、季、年控件標記
      { diseaseCode: "0", diseaseName: "0", checked: true },
      { diseaseCode: "1", diseaseName: "1", checked: false },
      { diseaseCode: "2", diseaseName: "2", checked: false },
    ],
    pressList: [//氣壓、大氣、OX、頻率、重量控件標記
      { diseaseCode: "0", diseaseName: "0", checked: true },
      { diseaseCode: "1", diseaseName: "1", checked: false },
      { diseaseCode: "2", diseaseName: "2", checked: false },
      { diseaseCode: "3", diseaseName: "3", checked: false },
      { diseaseCode: "4", diseaseName: "4", checked: false },
    ],
    list: [{
      username: "2021-7-6",
      send_timestamp: "120",
      centent: "閱讀,",
      total_likes: 2,
      unit: "mmhg"
    },
    ],
    HistoryDataList: [{
      data_times:'2022/12/01 10:11:02',
      values:'86/142',
      unit:'mmhg'
    },
    {
      data_times:'2022/11/30 08:01:52',
      values:'82/140',
      unit:'mmhg'
    }],//歷史數(shù)據(jù)
    templeDataList: [{}],//臨時接收歷史數(shù)據(jù)
    patientId:""
  },

  // 頁面加載
  onLoad(options) {
    var bloodTagss = options.bloodTag;

    this.data.patientId=""+ options.patientId;
    // console.log("======頁面加載==獲取病人id====" + this.data.patientId)

    //頭部時間
    var timeStamp = new Date();
    var titledt = this.formatDate(timeStamp);
    this.setData({
      titleDate: titledt
    });

  },

  onShow() {

  },

  onReady: function () {

  },

  //氣壓歷史數(shù)據(jù)
  bloodPresure: function () {

    var that = this;
    that.setData({
      HistoryDataList: []
    })

  },

  // OX歷史數(shù)據(jù)
  bloodOxygen: function () {
    var that = this;
    that.setData({
      HistoryDataList: []
    });

  
  },

  //獲取歷史OX數(shù)據(jù)
  bloodSugerData: function () {
    var that = this;
    that.setData({
      HistoryDataList: []
    });


      that.getBloodSugarChart()
 

  },

  //心率歷史數(shù)據(jù)
  getDataList: function () {

    var that = this;
    that.setData({
      HistoryDataList: []
    })

    this.getHeartRata()
  },

  //體重歷史數(shù)據(jù)
  getWeightDataList: function () {
    var that = this;
    that.setData({
      HistoryDataList: []
    })
  },

  // 退出登錄
  logout: function () {
    wx.navigateBack({})
  },

  // 氣壓
  booldPress: function () {

    // 狀態(tài)切換
    let that = this;
    for (const key in that.data.pressList) {
      that.data.pressList[key].checked = false;
    }

    that.data.pressList[0].checked = true;
    this.setData({
      pressList: that.data.pressList
    })
    //數(shù)據(jù)處理  
    that.bloodPressureCurve();
  },

  // 大氣
  booldTa: function () {

    // 狀態(tài)切換
    let that = this;
    for (const key in that.data.pressList) {
      that.data.pressList[key].checked = false;
    }

    that.data.pressList[1].checked = true;

    this.setData({
      pressList: that.data.pressList
    })
    //數(shù)據(jù)處理  
    that.getBloodSugarChart()
  },

  // OX
  booldO: function () {
    // 狀態(tài)切換
    let that = this;
    for (const key in that.data.pressList) {
      that.data.pressList[key].checked = false;
    }

    that.data.pressList[2].checked = true;
    this.setData({
      pressList: that.data.pressList
    })
    //數(shù)據(jù)處理  
    that.getBloodOxygenChart()
  },

  //頻率
  booldHaert: function () {
    // 狀態(tài)切換
    let that = this;
    for (const key in that.data.pressList) {
      that.data.pressList[key].checked = false;
    }

    that.data.pressList[3].checked = true;
    this.setData({
      pressList: that.data.pressList
    })
    //數(shù)據(jù)處理  
    that.getHeartRata();
  },

  // 重量
  booldWeight: function () {
    // 狀態(tài)切換
    let that = this;
    for (const key in that.data.pressList) {
      that.data.pressList[key].checked = false;
    }

    that.data.pressList[4].checked = true;
    this.setData({
      pressList: that.data.pressList
    })
    //數(shù)據(jù)處理  weight


    that.weghtCurve();
  },

  // 周選擇
  weekSelcet: function () {
    // 狀態(tài)切換
    let that = this;
    for (const key in that.data.diseaseList) {
      that.data.diseaseList[key].checked = false;
    }

    that.data.diseaseList[0].checked = true;
    this.setData({
      diseaseList: that.data.diseaseList
    })
      
  },

  // 月度
  monthSelect: function () {
    // 狀態(tài)切換
    let that = this;
    for (const key in that.data.diseaseList) {
      that.data.diseaseList[key].checked = false;
    }

    that.data.diseaseList[1].checked = true;
    this.setData({
      diseaseList: that.data.diseaseList
    })
    // 數(shù)據(jù)處理

  },

  //年切換
  yearselect: function () {
    // 狀態(tài)切換
    let that = this;
    for (const key in that.data.diseaseList) {
      that.data.diseaseList[key].checked = false;
    }

    that.data.diseaseList[2].checked = true;
    this.setData({
      diseaseList: that.data.diseaseList
    })

  },

  //氣壓圖表數(shù)據(jù)
  bloodPressureCurve: function () {

    let option = {
      title: {
        text: 'mmhg',
        y: '5%',
        x: '2%',
        textStyle: {
          fontSize: 12,
          fontWeight: 'normal',
        },
      },
      color: ["#05c8ac", '#60A0ff'],  //線的顏色
      legend: {
        data: ['m壓', 'h壓'],    //標識哪個顏色對應(yīng)哪個數(shù)據(jù)
        padding: 1,   //   內(nèi)邊距
        x: '30%',
        y: '6%',
      },
      grid: {
        top: '24%',
        left: '3%',
        right: '4%',
        bottom: '11%',
        containLabel: true
      },
      xAxis: {//x軸
        type: 'category',
        data: [1,2,3,4,5,6]
      },
      yAxis: {//y軸
        type: 'value'
      },
      series: [
        {
          data: [110,102,103,99,98,140],
          name: "m壓",
          type: 'line',
          smooth: false,
          label: {
            show: true
          }
        },
        {
          data: [70,65,85,81,76,78],
          name: "h壓",
          type: 'line',
          smooth: false,
          label: {
            show: true
          }
        }
      ],
      dataZoom: [
        {
          type: 'inside',// 內(nèi)置于坐標系中
          show: false,
          left: 33, //滾動條靠左側(cè)的百分比
          start: 0,
          end: 80,
          xAxisIndex: [0]
        }, {
          type: 'inside',
          show: true,
          xAxisIndex: [0],
          start: 0,//滾動條的起始位置
          end: 0.25 //滾動條的截止位置(按比例分割你的柱狀圖x軸長度)
        }
      ]
    };

    chart.setOption(option);

  },

  //大氣圖表數(shù)據(jù)
  getBloodSugarChart: function () {

    let option = {
      title: {
        text: 'mg/dl',
        y: '3%',
        x: '2%',
        textStyle: {
          fontSize: 12,
          fontWeight: 'normal',
        },
      },
      color: ["#05c8ac"],  //線的顏色
      legend: {
        data: [''],    //標識哪個顏色對應(yīng)哪個數(shù)據(jù)
        padding: 1,   //   內(nèi)邊距
        x: '30%',
        y: '5%',
      },
      grid: {
        top: '24%',
        left: '3%',
        right: '4%',
        bottom: '11%',
        containLabel: true
      },
      xAxis: {//x軸
        type: 'category',
        data: ['11/01','11/02','11/03','11/04']
      },
      yAxis: {//y軸
        type: 'value'
      },
      series: [
        {
          data: [20,30,34,29],
          name: "大氣",
          type: 'line',
          smooth: false,
          label: {
            show: true
          }
        }, {
          data: [],
          name: "大氣",
          type: 'line',
          smooth: false,
          label: {
            show: true
          }
        }
      ],
      dataZoom: [
        {
          type: 'inside',// 內(nèi)置于坐標系中
          show: false,
          left: 33, //滾動條靠左側(cè)的百分比
          start: 0,
          end: 80,
          xAxisIndex: [0]
        }, {
          type: 'inside',
          show: true,
          xAxisIndex: [0],
          start: 0,//滾動條的起始位置
          end: 80 //滾動條的截止位置(按比例分割你的柱狀圖x軸長度)
        }
      ]
    };
    wx.hideToast()
    chart.setOption(option);
  },

  //OX圖表數(shù)據(jù)
  getBloodOxygenChart: function () {

    let option = {
      title: {
        text: '%',
        y: '3%',
        x: '2%',
        textStyle: {
          fontSize: 12,
          fontWeight: 'normal',
        },
      },
      color: ["#05c8ac"],  //線的顏色
      legend: {
        data: [''],    //標識哪個顏色對應(yīng)哪個數(shù)據(jù)
        padding: 1,   //   內(nèi)邊距
        x: '30%',
        y: '5%',
      },
      grid: {
        top: '24%',
        left: '3%',
        right: '4%',
        bottom: '11%',
        containLabel: true
      },
      xAxis: {//x軸
        type: 'category',
        data: [1,2,3,4,5]
      },
      yAxis: {//y軸
        type: 'value'
      },
      series: [
        {
          data: [70,72,74,80,65],
          name: "OX",
          type: 'line',
          smooth: false,
          label: {
            show: true
          }
        }, {
          data: [],
          name: "",
          type: 'line',
          smooth: false,
          label: {
            show: true
          }
        }
      ],
      dataZoom: [
        {
          type: 'inside',// 內(nèi)置于坐標系中
          show: false,
          left: 33, //滾動條靠左側(cè)的百分比
          start: 0,
          end: 80,
          xAxisIndex: [0]
        }, {
          type: 'inside',
          show: false,
          xAxisIndex: [0],
          start: 0,//滾動條的起始位置
          end: 80, //滾動條的截止位置(按比例分割你的柱狀圖x軸長度)
        }
      ]
    };
    wx.hideToast()
    chart.setOption(option);
  },

  //心率圖表數(shù)據(jù)處理
  getHeartRata: function () {
    
    let option = {
      title: {
        text: 'bmp',
        y: '5%',
        x: '2%',
        textStyle: {
          fontSize: 12,
          fontWeight: 'normal',
        },
      },
      color: ["#05c8ac"],  //線的顏色
      legend: {
        data: [''],    //標識哪個顏色對應(yīng)哪個數(shù)據(jù)
        padding: 1,   //   內(nèi)邊距
        x: '30%',
        y: '6%',
      },
      grid: {
        top: '24%',
        left: '3%',
        right: '4%',
        bottom: '11%',
        containLabel: true
      },
      xAxis: {//x軸
        type: 'category',
        data: [1,2,3,4,5]
      },
      yAxis: {//y軸
        type: 'value'
      },
      series: [
        {
          data: [88,90,89,93,100],
          name: "收縮壓",
          type: 'line',
          smooth: false,
          label: {
            show: true
          }
        },
        {
          data: [],
          name: "",
          type: 'line',
          smooth: false,
          label: {
            show: true
          }
        }
      ],
      dataZoom: [
        {
          type: 'inside',// 內(nèi)置于坐標系中
          show: false,
          left: 33, //滾動條靠左側(cè)的百分比
          start: 0,
          end: 80,
          xAxisIndex: [0]
        }, {
          type: 'inside',
          show: false,
          xAxisIndex: [0],
          start: 0,//滾動條的起始位置
          end: 80 //滾動條的截止位置(按比例分割你的柱狀圖x軸長度)
        }
      ]
    };

    chart.setOption(option);
  },

  //重量
  weghtCurve: function () {
 
    let option = {
      title: {
        text: 'kg',
        y: '5%',
        x: '2%',
        textStyle: {
          fontSize: 12,
          fontWeight: 'normal',
        },
      },
      color: ["#05c8ac"],  //線的顏色
      legend: {
        data: [''],    //標識哪個顏色對應(yīng)哪個數(shù)據(jù)
        padding: 1,   //   內(nèi)邊距
        x: '30%',
        y: '6%',
      },
      grid: {
        top: '24%',
        left: '3%',
        right: '4%',
        bottom: '11%',
        containLabel: true
      },
      xAxis: {//x軸
        type: 'category',
        data: ['11/01','11/02','11/03','11/04','11/05']
      },
      yAxis: {//y軸
        type: 'value'
      },
      series: [
        {
          data: [66,65,59,68,70],
          name: "收縮壓",
          type: 'line',
          smooth: false,
          label: {
            show: true
          }
        },
        {
          data: [],
          name: "",
          type: 'line',
          smooth: false,
          label: {
            show: true
          }
        }
      ],
      dataZoom: [
        {
          type: 'inside',// 內(nèi)置于坐標系中
          show: false,
          left: 33, //滾動條靠左側(cè)的百分比
          start: 0,
          end: 80,
          xAxisIndex: [0]
        }, {
          type: 'inside',
          show: true,
          xAxisIndex: [0],
          start: 0,//滾動條的起始位置
          end: 0.25 //滾動條的截止位置(按比例分割你的柱狀圖x軸長度)
        }
      ]
    };

    chart.setOption(option);
  },

  //轉(zhuǎn)換為時間格式
  formatDate(time: Date) {
    let show_day = new Array('周日', '周一', '周二', '周三', '周四', '周五', '周六');
    var date = new Date(time);

    date.setDate(date.getDate());
    let weekDay = date.getDay();
    var weekDate = show_day[weekDay]

    var YY = date.getFullYear() + '-';
    var MM = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '月';
    var DD = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate());
    var hh = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours());
    var mm = ':' + (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes());
    var ss = ':' + (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
    return MM + DD + "日 " + weekDate + " " + hh + mm;
  },

  onPullDownRefresh() {
    //數(shù)據(jù)處理  
    var timeStamp = new Date();
    var titledt = this.formatDate(timeStamp);
    this.setData({
      titleDate: titledt
    })
    console.log("============" + this.formatDate(timeStamp))
  },
})

// 初始化圖表函數(shù)
function initChart(canvas: any, width: any, height: any, dpr: any) {
  chart = echarts.init(canvas, null, {
    width: width,
    height: height,
    devicePixelRatio: dpr
  })

  // canvas.setChart(chart)
  // 顯示Echarts圖表類型信息,可以去Echarts官網(wǎng)復(fù)制粘貼
  let option = {
    title: {
      text: 'mmhg',
      y: '5%',
      x: '2%',
      textStyle: {
        fontSize: 12,
        fontWeight: 'normal',
      },
    },
    color: ["#05c8ac", '#60A0ff'],  //線的顏色
    legend: {
      data: ['m壓', 'h壓'],     //標識哪個顏色對應(yīng)哪個數(shù)據(jù)
      padding: 1,   //   內(nèi)邊距
      x: '30%',
      y: '6%',
    },
    grid: {
      top: '24%',
      left: '3%',
      right: '4%',
      bottom: '11%',
      containLabel: true
    },
    xAxis: {//x軸
      type: 'category',
      data: [1,2,3,4,5,6]
    },
    yAxis: {//y軸
      type: 'value'
    },
    series: [
      {
        data: [110,102,103,99,98,140],
        name: "m壓",
        type: 'line',
        smooth: false,
        label: {
          show: true
        }
      },
      {
        data: [70,65,85,81,76,78],
        name: "h壓",
        type: 'line',
        smooth: false,
        label: {
          show: true
        }
      }
    ],
    dataZoom: [
      {
        type: 'inside',// 內(nèi)置于坐標系中
        show: false,
        left: 33, //滾動條靠左側(cè)的百分比
        start: 0,
        end: 80,
        xAxisIndex: [0]
      }, {
        type: 'inside',
        show: true,
        xAxisIndex: [0],
        start: 0,//滾動條的起始位置
        end: 0.25 //滾動條的截止位置(按比例分割你的柱狀圖x軸長度)
      }
    ]
  };

  chart.setOption(option);
  return chart;
}

到了這里,關(guān)于微信小程序使用Echart實現(xiàn)折線圖案例的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • 微信小程序echart導(dǎo)出圖片

    微信小程序echart導(dǎo)出圖片

    echarts版本5.1.0 用到的echarts組件是uni插件市場的echart組件 關(guān)鍵代碼是 ?

    2024年02月10日
    瀏覽(17)
  • 微信小程序Canvas繪制曲線圖餅圖柱狀圖雷達圖蛛網(wǎng)圖實現(xiàn)(附源碼)
  • uni-app+vue2 微信小程序 使用canvas繪制折線圖/波形圖

    uni-app+vue2 微信小程序 使用canvas繪制折線圖/波形圖

    ? 接口返回一個數(shù)組,每一項均是一個數(shù)字,代表著y坐標,x坐標需自己處理。 我的數(shù)據(jù)是1024個浮點數(shù),在-10到10之間 波形圖需要xy軸縮放功能,用c3的 transform: scale()是不行的,至少會失真。 然后背景的格子,我這里是每個格子要求100個點,初始縮放下是11個格子,10條線(

    2024年04月26日
    瀏覽(26)
  • echart 實現(xiàn)多柱狀圖+多折線圖

    echart 實現(xiàn)多柱狀圖+多折線圖

    當(dāng)圖表中存在多個柱狀圖時,如何讓每條折線折點對應(yīng)在每個柱狀圖中點位置? ?配置如下: 圖例如下:

    2024年02月11日
    瀏覽(28)
  • 【微信小程序】echart中canvas原生組件層級太高遮擋vantui中的組件

    【微信小程序】echart中canvas原生組件層級太高遮擋vantui中的組件

    之前的問題圖片如下: 最開始想到的方案是降低canvas的層級,但是canvas是原生組件,他的層級是沒法改變 所以又想到改變vant組件的層級,但是一樣無果。。。 隨后,看到網(wǎng)上大篇幅的都是使用顯示隱藏來操控picker的,這樣會如果頁面可以滑動,就導(dǎo)致用戶還是可以看到ec

    2024年02月13日
    瀏覽(35)
  • 微信小程序--》從零實現(xiàn)小程序項目案例

    微信小程序--》從零實現(xiàn)小程序項目案例

    ???作者簡介:大家好,我是亦世凡華、渴望知識儲備自己的一名在校大學(xué)生 ??個人主頁:亦世凡華、 ??系列專欄:微信小程序 ??座右銘:人生亦可燃燒,亦可腐敗,我愿燃燒,耗盡所有光芒。 ??引言 ?????? ?經(jīng)過web前端開發(fā)的學(xué)習(xí),相信大家對于前端開發(fā)有了一

    2024年02月03日
    瀏覽(13)
  • 微信小程序?qū)崿F(xiàn)生成分享海報案例

    微信小程序?qū)崿F(xiàn)生成分享海報案例

    一、引入插件painter (1)克隆地址:https://gitcode.net/mirrors/Kujiale-Mobile/Painter (2)下載的 painter 放到小程序的 components 目錄下 二、頁面中引入插件 (1)頁面的 json 文件 (2)頁面的 wxml 文件 其中 painter 插件可以獲取繪制出來的圖片路徑, image 標簽展示出來 三、繪制海報 1、

    2024年02月08日
    瀏覽(22)
  • 微信小程序引用echart報錯 ,上傳代碼報t.addEventListener is not a function

    最近做項目用到echart新版本,5.4.0。在微信開發(fā)工具里面可以正常運行。代碼上傳的時候就會報錯,真機和預(yù)覽也報錯。 解決辦法 在ec-canvas文件夾下的 wx-canvas.js文件中添加 addEventListener() {} 空函數(shù),如下: 再上傳就不會出錯了

    2024年02月11日
    瀏覽(17)
  • 微信小程序?qū)崿F(xiàn)商品加入購物車案例

    微信小程序?qū)崿F(xiàn)商品加入購物車案例

    思考: 購物車中的數(shù)據(jù)保存在哪里?用哪種數(shù)據(jù)結(jié)構(gòu)進行保存? 小程序中可能有多個頁面需要對購物車中的數(shù)據(jù)進行操作,因此我們想到把數(shù)據(jù)存到全局中。可以使用 wx.setStorageSync() 儲存,用 wx.getStorageSync() 進行獲取,以數(shù)組格式方便對數(shù)據(jù)進行操作。 一、商品加入購物車

    2024年02月10日
    瀏覽(19)
  • 【微信小程序(黑馬程序課程)案例實現(xiàn)——本地生活的首頁基本布局】

    【微信小程序(黑馬程序課程)案例實現(xiàn)——本地生活的首頁基本布局】

    一. 新建一個項目 二. 添加頁面和刪除頁面 (1) 添加頁面 ——app.json/pages中添加路徑,并刪除原有的路徑 (2)刪除頁面——路徑已經(jīng)被刪除,現(xiàn)在刪除文件 三.設(shè)置導(dǎo)航欄效果 ——app.json/windows中更改 效果圖: 代碼如下: 四.設(shè)置tabBar效果 ——在app.json中創(chuàng)建tabBar(與win

    2024年04月16日
    瀏覽(36)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包