1、clone官方库echarts-for-weixin到本地,将其中的ec-canvas目录复制到自己项目的某个目录下(如components)

2、在自己的组件或页面中(.json文件),按如下方式使用,路径根据自己的项目具体设置

{
  "usingComponents": {
    "ec-canvas": "../components/ec-canvas/ec-canvas"
  }
}
3、在页面中引用(.wxml)
样式:
/* 折线图 */
.overview-charts {
width: 100%;
height: 560rpx;
}
 
<view class="overview-charts"> <ec-canvas style="width: 100%; height: 560rpx;z-index: 1;" id="my-analysis-chart" canvas-id="my-analysis-line" ec="{{ overviewChart }}"></ec-canvas> </view>

4、在.js文件中,获取图标数据,然后获取echarts实例,设置数据和配置项

data: {
overviewChart: {
      // 将 lazyLoad 设为 true 后,需要手动初始化图表
      lazyLoad: true
    },
}

// 折线图
  initLineChart(chartData) {
    let myAnalysisComponent = this.selectComponent('#my-analysis-chart');
    myAnalysisComponent.init((canvas, width, height, dpr) => {
      // 获取组件的 canvas、width、height 后的回调函数
      // 初始化图表
      const lineChart = echarts.init(canvas, null, {
        width: width,
        height: height,
        devicePixelRatio: dpr
      });
      this.setLineChartOption(lineChart, chartData)
      return lineChart;
    });
  },
  setLineChartOption(chart, chartData) {
    const option = {
      grid: {
        top: 10,
        left: '2%',
        right: '2%',
        bottom: '3%',
        containLabel: true
      },
      tooltip: {
        trigger: 'item',
        borderColor: '#FFFFFF',
        formatter: (params) => {
          console.log('params--',params);
          let str = params.name + '\n'
          str += `${params.marker}${params.seriesName}: ${params.value}`
          return str;
        }
      },
      dataZoom: [
        //滑动条
        {
          xAxisIndex: 0, //这里是从X轴的0刻度开始
          show: true, //是否显示滑动条,不影响使用
          type: "inside", // 这个 dataZoom 组件是 slider 型 dataZoom 组件
          startValue: 0, // 从头开始。
          endValue: 6, // 一次性展示6个。
          zoomLock: false,
        },
      ],
      xAxis: {
        type: 'category',
        data: chartData.xdata || [],
        axisLabel: {
          interval: 0,
          rotate: 70
        }
      },
      yAxis: {
        minInterval: 1,
        type: 'value'
      },
      series: [
        {
          name: '折线图',
          lineStyle: {
            color: '#0075EF'
          },
          areaStyle: {
            color: {
              type: 'linear',
              x: 0,
              y: 0,
              x2: 0,
              y2: 1,
              colorStops: [{
                offset: 0, color: 'rgba(0,117,239,0.15)' // 0% 处的颜色
              }, {
                offset: 1, color: 'rgba(0,117,239,0)' // 100% 处的颜色
              }],
              global: false // 缺省为 false
            }
          },
          symbol: 'circle',
          symbolSize: '6',
          itemStyle: {
            // 设置symbol的颜色
            normal: {
              color: '#0075EF'
            }
          },
          data: chartData.ydata || [],
          type: 'line'
        }
      ]
    };
    chart.setOption(option);
    return chart;
  },

 

 
posted @ 2025-01-06 17:23 xiaoxiaoxigua 阅读(182) 评论(0) 推荐(0) 编辑
摘要: 在手机端宽度不够的时候可以设置横坐标区域滚动, 主要是设置一下zoom配置项 dataZoom: [ //滑动条 { xAxisIndex: 0, //这里是从X轴的0刻度开始 show: true, //是否显示滑动条,不影响使用 type: "inside", // 这个 dataZoom 组件 阅读全文
posted @ 2024-12-20 18:44 xiaoxiaoxigua 阅读(238) 评论(0) 推荐(0) 编辑
摘要: 1、主要是使用期限选择器的 这个方法Picker Options 文档介绍 onPick 选中日期后会执行的回调,只有当 daterange 或 datetimerange 才生效 Function({ maxDate, minDate }) 2、代码实现 定义一个变量记录 当前点击的起始日期 us 阅读全文
posted @ 2024-12-18 10:04 xiaoxiaoxigua 阅读(104) 评论(0) 推荐(0) 编辑
摘要: 绑定 @input 事件方法 formInput formInput (val, prop) { let replacevalue = ("" + val) // 第一步:转成字符串 .replace(/[^\d^\.]+/g, "") // eslint-disable-line .replace 阅读全文
posted @ 2024-12-10 14:36 xiaoxiaoxigua 阅读(272) 评论(0) 推荐(0) 编辑
摘要: 正常一个列表有编辑和新增弹框,弹框里面有el-date-picker type=range (这是一个共用组件),如果先点击编辑,选择日期后,再去新增,这是会发现选择日期范围选择框选择不了,这时候可以把 公用的弹框组件用 template 包裹起来,加个v-if。 阅读全文
posted @ 2024-09-19 17:29 xiaoxiaoxigua 阅读(210) 评论(0) 推荐(0) 编辑
摘要: 问题描述,data里面数据也设置了id({id:1})这样设置的,links里面设置了source和target({source:0,target:1}),但是运行发现只显示了node没显示连线(edge),去看了文档描述 1、source stringnumber 边的源节点名称的字符串,也支持使 阅读全文
posted @ 2024-08-05 17:31 xiaoxiaoxigua 阅读(221) 评论(1) 推荐(0) 编辑
摘要: <template slot="testContent" slot-scope="{record}"> <a-tooltip @mouseenter="showToolTip" overlayClassName="customtooltip_class" destroyTooltipOnHide> 阅读全文
posted @ 2024-07-05 16:28 xiaoxiaoxigua 阅读(252) 评论(0) 推荐(0) 编辑
摘要: 阅读全文
posted @ 2024-04-22 19:13 xiaoxiaoxigua 阅读(3) 评论(0) 推荐(0) 编辑
摘要: 解决方法:1、设置border 2、设置padding 3、价格overflow:hidden 阅读全文
posted @ 2024-04-21 07:43 xiaoxiaoxigua 阅读(4) 评论(0) 推荐(0) 编辑
摘要: 1、当一个页面有多个类型输入框时,联系人是 password 类型,联系地址是text类型, (1)当切换regType==1时联系地址还是password类型 (2)当限制输入长度时input的value值和v-model取得值也是不一样的 <div class="lfItem" v-if="re 阅读全文
posted @ 2023-08-11 10:44 xiaoxiaoxigua 阅读(117) 评论(0) 推荐(0) 编辑
点击右上角即可分享
微信分享提示