怎么在微信小程序中使用wx-charts图表插件

发布时间:2021-04-01 18:04:00 作者:Leah
来源:亿速云 阅读:370

今天就跟大家聊聊有关怎么在微信小程序中使用wx-charts图表插件,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

支持图标类型

如何使用?

1. 直接引用编译好的文件 dist/charts.js(js下载地址)

.wxml中定义

<canvas canvas-id="lineCanvas" disable-scroll="true" class="canvas"></canvas>

canvas-id与new wxCharts({canvasId:”})中canvasId一致

2. 命令行

git clone github.com/xiaolin3303/wx-charts.git
npm install rollup -g
npm install
rollup -c #或者 rollup --config rollup.config.prod.js

参数说明

optsObject
opts.canvasIdString required微信小程序canvas-id
opts.widthNumber requiredcanvas宽度,单位为px
opts.heightNumber requiredcanvas高度,单位为px
opts.titleObject(only for ring chart)
opts.title.nameString标题内容
opts.title.fontSizeNumber标题字体大小(可选,单位为px)
opts.title.colorString标题颜色(可选)
opts.subtitleObject(only for ring chart)
opts.subtitle.nameString副标题内容
opts.subtitle.fontSizeNumber副标题字体大小(可选,单位为px)
opts.subtitle.colorString副标题颜色(可选)
opts.animationBoolean default true是否动画展示
opts.legendBoolen default true是否显示图表下方各类别的标识
opts.typeString required图表类型,可选值为pie, line, column, area……
opts.categoriesArray required(饼图、圆环图不需要) 数据类别分类
opts.dataLabelBoolean default true是否在图表中显示数据内容值
opts.dataPointShapeBoolean default true是否在图表中显示数据点图形标识
opts.xAxisObjectX轴配置
opts.xAxis.disableGridBoolean default false不绘制X轴网格
opts.yAxisObjectY轴配置
opts.yAxis.formatFunction自定义Y轴文案显示
opts.yAxis.minNumberY轴起始值
opts.yAxis.maxNumberY轴终止值
opts.yAxis.titleStringY轴title
opts.yAxis.disabledBoolean default false不绘制Y轴
opts.seriesArray required数据列表

数据列表每项结构定义

dataItemObject
dataItem.dataArray required (饼图、圆环图为Number) 数据
dataItem.colorString 例如#7cb5ec 不传入则使用系统默认配色方案
dataItem.nameString 数据名称
dateItem.formatFunction 自定义显示数据内容

详见demo(具体demo git地址)

1.pie

new wxCharts({
  animation: true, //是否有动画
  canvasId: 'pieCanvas',
  type: 'pie',
  series: [{
    name: '成交量1',
    data: 15,
  }, {
    name: '成交量2',
    data: 35,
  }, {
    name: '成交量3',
    data: 78,
  }],
  width: windowWidth,
  height: 300,
  dataLabel: true,
 });
}

怎么在微信小程序中使用wx-charts图表插件

2. ring

new wxCharts({
  animation: true,
  canvasId: 'ringCanvas',
  type: 'ring',
  extra: {
    ringWidth: 25,
    pie: {
      offsetAngle: -45
    }
  },
  title: {
    name: '70%',
    color: '#7cb5ec',
    fontSize: 25
  },
  subtitle: {
    name: '收益率',
    color: '#666666',
    fontSize: 15
  },
  series: [{
    name: '成交量1',
    data: 15,
    stroke: false
  }, {
    name: '成交量2',
    data: 35,
     stroke: false
  }, {
    name: '成交量3',
    data: 78,
    stroke: false
  }, {
    name: '成交量4',
    data: 63,
     stroke: false
  }],
  disablePieStroke: true,
  width: windowWidth,
  height: 200,
  dataLabel: false,
  legend: false,
  padding: 0
});

怎么在微信小程序中使用wx-charts图表插件

3. line

new wxCharts({
  canvasId: 'lineCanvas',
  type: 'line',
  categories: simulationData.categories,
  animation: true,
  background: '#f5f5f5',
  series: [{
    name: '成交量1',
    data: simulationData.data,
    format: function (val, name) {
      return val.toFixed(2) + '万';
    }
  }, {
    name: '成交量2',
    data: [2, 0, 0, 3, null, 4, 0, 0, 2, 0],
    format: function (val, name) {
      return val.toFixed(2) + '万';
    }
  }],
  xAxis: {
    disableGrid: true
  },
  yAxis: {
    title: '成交金额 (万元)',
    format: function (val) {
      return val.toFixed(2);
    },
    min: 0
  },
  width: windowWidth,
  height: 200,
  dataLabel: false,
  dataPointShape: true,
  extra: {
    lineStyle: 'curve'
  }
});

怎么在微信小程序中使用wx-charts图表插件

4. column

new wxCharts({
  canvasId: 'columnCanvas',
  type: 'column',
  animation: true,
  categories: chartData.main.categories,
  series: [{
    name: '成交量',
    data: chartData.main.data,
    format: function (val, name) {
      return val.toFixed(2) + '万';
    }
  }],
  yAxis: {
    format: function (val) {
      return val + '万';
    },
    title: 'hello',
    min: 0
  },
  xAxis: {
    disableGrid: false,
    type: 'calibration'
  },
  extra: {
    column: {
      width: 15
    }
  },
  width: windowWidth,
  height: 200,
});

怎么在微信小程序中使用wx-charts图表插件

5. area

new wxCharts({
  canvasId: 'areaCanvas',
  type: 'area',
  categories: ['1', '2', '3', '4', '5', '6'],
  animation: true,
  series: [{
    name: '成交量1',
    data: [32, 45, 0, 56, 33, 34],
    format: function (val) {
      return val.toFixed(2) + '万';
    }
  }, {
   name: '成交量2',
   data: [15, 20, 45, 37, 4, 80],
   format: function (val) {
    return val.toFixed(2) + '万';
   },
  }],
  yAxis: {
    title: '成交金额 (万元)',
    format: function (val) {
      return val.toFixed(2);
    },
    min: 0,
    fontColor: '#8085e9',
    gridColor: '#8085e9',
    titleFontColor: '#f7a35c'
  },
  xAxis: {
    fontColor: '#7cb5ec',
    gridColor: '#7cb5ec'
  },
  extra: {
    legendTextColor: '#cb2431'
  },
  width: windowWidth,
  height: 200
});

怎么在微信小程序中使用wx-charts图表插件

6.radar

new wxCharts({
  canvasId: 'radarCanvas',
  type: 'radar',
  categories: ['1', '2', '3', '4', '5', '6'],
  series: [{
    name: '成交量1',
    data: [90, 110, 125, 95, 87, 122]
  }],
  width: windowWidth,
  height: 200,
  extra: {
    radar: {
      max: 150
    }
  }
});

怎么在微信小程序中使用wx-charts图表插件

看完上述内容,你们对怎么在微信小程序中使用wx-charts图表插件有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注亿速云行业资讯频道,感谢大家的支持。

推荐阅读:
  1. 微信小程序如何使用蓝牙小插件
  2. wx-charts中如何使用微信小程序图表插件

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

微信小程序 wx-charts

上一篇:metaclass怎么在python中使用

下一篇:如何在jQuery中使用Migrate 插件

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》