首页 > 专题 > 微信 > 正文

wx-charts 微信小程序图表插件的具体使用

2020-02-25 01:09:18
字体:
来源:转载
供稿:网友

微信小程序图表插件(wx-charts)基于canvas绘制,体积小巧,支持图表类型饼图、线图、柱状图 、区域图等图表图形绘制,目前wx-charts是微信小程序图表插件中比较强大好使的一个

支持图标类型

饼图 pie 圆环图 ring 线图 line 柱状图 column 区域图 area 雷达图 radar

如何使用?

直接引用编译好的文件 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.gitnpm install rollup -gnpm installrollup -c 或者 rollup --config rollup.config.prod.js

参数说明

opts             Objectopts.canvasId        String required          微信小程序canvas-idopts.width          Number required        canvas宽度,单位为pxopts.height         Number required        canvas高度,单位为pxopts.title          Object      (only for ring chart)opts.title.name       String      标题内容opts.title.fontSize     Number      标题字体大小(可选,单位为px)opts.title.color       String      标题颜色(可选)opts.subtitle        Object     (only for ring chart)opts.subtitle.name      String      副标题内容opts.subtitle.fontSize    Number     副标题字体大小(可选,单位为px)opts.subtitle.color     String     副标题颜色(可选)opts.animation        Boolean default true     是否动画展示opts.legend         Boolen default true    是否显示图表下方各类别的标识opts.type          String required 图表类型,可选值为pie, line, column, area……opts.categories       Array required    (饼图、圆环图不需要) 数据类别分类opts.dataLabel        Boolean default true   是否在图表中显示数据内容值opts.dataPointShape     Boolean default true  是否在图表中显示数据点图形标识opts.xAxis          Object    X轴配置opts.xAxis.disableGrid    Boolean default false   不绘制X轴网格opts.yAxis          Object  Y轴配置opts.yAxis.format      Function      自定义Y轴文案显示opts.yAxis.min        Number    Y轴起始值opts.yAxis.max        Number      Y轴终止值opts.yAxis.title       String    Y轴titleopts.yAxis.disabled     Boolean default false    不绘制Y轴opts.series         Array required    数据列表

数据列表每项结构定义

dataItem           ObjectdataItem.data         Array required (饼图、圆环图为Number) 数据dataItem.color        String 例如#7cb5ec 不传入则使用系统默认配色方案dataItem.name         String 数据名称dateItem.format        Function 自定义显示数据内容

详见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, });}            
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表