AntV - F6 小程序移动端图表组件(微信版)

AntV 蚂蚁新出的可视化组件,分为很多部分 官网
F6 文档链接

  1. 安装 npm install --save @antv/f6-wx
  2. 微信开发工具 - 工具 - 构建npm
  3. 组件使用 分为图配置 / 树图配置

4. 图配置

wxml
<view>
  <f6-canvas
    width="{
    {canvasWidth}}"
    height="{
    {canvasHeight}}"
    pixelRatio="{
    {pixelRatio}}"
    bind:onInit="handleCanvasInit"
    bind:onTouchEvent="handleTouch"
  />
</view>
json
{
   
  "usingComponents": {
   
    "f6-canvas": "@antv/f6-wx/canvas/canvas"
  }
}
js
import F6 from '@antv/f6-wx';
import force from '@antv/f6-wx/extends/layout/forceLayout';

/**
 * 基本力导向布局及节点拖拽
 */

Page({
   
  canvas: null,
  ctx: null,
  renderer: '', // mini、mini-native等,F6需要,标记环境
  graph: null,

  data: {
   
    width: 375,
    height: 600,
    pixelRatio: 1,
    forceMini: false,
  },

  onLoad() {
   
    F6.registerLayout('force', force);
    // 同步获取window的宽高
    const {
    windowWidth, windowHeight, pixelRatio } = wx.getSystemInfoSync();

    this.setData({
   
      canvasWidth: windowWidth,
      canvasHeight: windowHeight,
      pixelRatio,
    });
  },

  /**
   * 初始化cnavas回调,缓存获得的context
   * @param {*} ctx 绘图context
   * @param {*} rect 宽高信息
   * @param {*} canvas canvas对象,在render为mini时为null
   * @param {*} renderer 使用canvas 1.0还是canvas 2.0,mini | mini-native
   */
  handleCanvasInit(event) {
   
    const {
    ctx, canvas, renderer } = event.detail;
    this.isCanvasInit = true;
    this.ctx = ctx;
    this.renderer = renderer;
    this.canvas = canvas;
    this.updateChart();
  },

  /**
   * canvas派发的事件,转派给graph实例
   */
  handleTouch(e) {
   
    this.graph && this.graph.emitEvent(e.detail);
  },

  updateChart() {
   
    const {
    canvasWidth, canvasHeight, pixelRatio } = this.data;
    const data = {
   
      nodes: [
        {
    id: 'node0', size: 50 },
        {
    id: 'node1', size: 30 },
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值