wx-charts
微信小程序主流的图表工具
基于 Canvas,体积小
注意:wx-charts 插件无法在组件内使用。
import wxCharts from '../../utils/wxcharts-min.js' 1 wxml 中定义
<canvas canvas-id="pieCanvas" disable-scroll="true" class="pieCanvas" style="width:300px; height:300px;"></canvas> 1
canvas-id 与 new wxCharts({canvasId: ‘’}) 中的 canvasId 值一致。
let chart = new wxCharts({ animation: true, canvasId: 'pieCanvas', type: 'pie', series: [{ name: '成交量1', data: 15, }, { name: '成交量2', data: 35, }, { name: '成交量3', data: 78, }], width: 300, height: 300, })
1234567891011121314151617
2. 圆环图 ring
let chart = 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: 300, height: 300, dataLabel: false, legend: false, padding: 0 })
1234567891011121314151617181920212223242526272829303132333435363738394041424344let chart = new wxCharts({ canvasId: 'lineCanvas', type: 'line', categories: ['2016-1', '2016-2', '2016-3', '2016-4', '2016-5', '2016-6', '2016-7', '2016-8', '2016-9', '2016-10'], animation: true, series: [{ name: '成交量1', data: [12,10,18,16,19,13,11,10,15,14], 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: 300, height: 300, dataLabel: false, dataPointShape: true, extra: { lineStyle: 'curve' } })
123456789101112131415161718192021222324252627282930313233343536let chart = new wxCharts({ canvasId: 'columnCanvas', type: 'column', animation: true, categories: ['2012', '2013', '2014', '2015'], series: [{ name: '成交量', data: [15, 20, 45, 37], format: function (val, name) { return val.toFixed(2) + '万'; } }], yAxis: { format: function (val) { return val + '万'; }, title: 'Column', min: 0 }, xAxis: { disableGrid: false, type: 'calibration' }, extra: { column: { width: 15 } }, width: 300, height: 200, });
12345678910111213141516171819202122232425262728293031let chart = 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: 300, height: 250 });
1234567891011121314151617181920212223242526272829303132333435363738let chart = new wxCharts({ canvasId: 'radarCanvas', type: 'radar', categories: ['1', '2', '3', '4', '5', '6'], series: [{ name: '成交量1', data: [90, 110, 125, 95, 87, 122] }], width: 300, height: 200, extra: { radar: { max: 150 } } });
12345678910111213141516数据列表series每项参数说明
参数类型说明dataItemObjectdataItem.dataArray Required饼图、圆环图为Number数据,如果传入null,图表、该处出现断点dataItem.colorString不传入则使用系统默认的配色方案dataItem.nameString数据名称dataItem.formatFunction自定义显示数据内容ring 图表相关配置
参数类型说明opts.titleObject仅支持 ring 图表类型opts.title.nameString标题内容opts.title.fontSizeNumber标题字体大小,单位pxopts.title.colorString标题颜色opts.title.offsetXNumber标题横向位置偏移量,单位px,默认0opts.subtitleObject仅支持 ring 图表类型opts.subtitle.nameString副标题内容opts.subtitle.fontSizeNumber副标题字体大小,单位pxopts.subtitle.colorString副标题颜色opts.subtitle.offsetXNumber副标题横向位置偏移量,单位px,默认0radar 图表相关配置
参数类型说明opts.extra.radarObjectradar图表相关配置opts.extra.radar.maxNumber数据区间最大值,用于调整数据显示的比例,默认series data的最大值opts.extra.radar.labelColorString各项标识文案的颜色,默认#666opts.extra.radar.gridColorString雷达图网格颜色,默认#cccpie、ring 图表相关配置
参数类型说明opts.disablePieStrokeBoolean不绘制pie、ring图表各区块的白色分割线,默认falseopts.extra.pieObjectpie、ring图表相关配置opts.extra.pie.offsetAngleNumber起始角度偏移度数,顺时针方向,起点为3点钟位置(比如要设置起点为12点钟位置,即逆时针偏移90度,传入-90即可),默认0<canvas bindtouchstart="touchHandler" canvas-id="pieCanvas" disable-scroll="true" class="pieCanvas" style="width:300px; height:300px;"></canvas> touchHandler (e) { let index = this.data.chart.getCurrentDataIndex(e); console.log('index', index) } 123456 howToolTip(e, options?) 图表中展示数据详细内容(目前仅支持 line 和 area 图表类型),详见githubscrollStart(e), scroll(e), scrollEnd(e) 设置支持图表拖拽系列事件(支持 line,area,column),详见github
renderComplete 图表渲染完成(如果有动画,则动画完成时触发)
chart.addEventListener('renderComplete', () => { // your code here }); 123
GitHub 地址
https://github.com/xiaolin3303/wx-charts
相关知识
初尝微信小程序(浪漫调酒师)
【微信小程序开发实战项目】——如何制作一个属于自己的花店微信小程序(2)
【微信小程序开发实战项目】——如何制作一个属于自己的花店微信小程序(3)
【微信小程序开发实战项目】——花店微信小程序实战项目(4)
微信小程序 swiper + scroll
微信小程序
【微信小程序开发实战项目】——如何制作一个属于自己的花店微信小程序(1)
【源码+文档】基于微信小程序的网上花店系统
微信小程序七夕节礼物
使用微信小程序调用飞桨PaddleX平台自行训练的模型——微信小程序用训练的牡丹花模型Demo测试
网址: 【微信小程序】wx https://m.huajiangbk.com/newsview1545045.html
上一篇: F2图表插件绘制圆角柱形图 |
下一篇: 微信小程序中使用图表插件 wx |