wx-charts 微信小程序图表插件

阅读数:9460

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

支持图标类型

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

如何使用?

  1. 直接引用编译好的文件 dist/charts.js(js下载地址) 
    .wxml中定义
<canvas canvas-id="lineCanvas" disable-scroll="true" class="canvas"></canvas>
  • 1

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
  • 1
  • 2
  • 3
  • 4

参数说明

opts                         Object
opts.canvasId                String required                    微信小程序canvas-id
opts.width                   Number required                canvas宽度,单位为px
opts.height                  Number required                canvas高度,单位为px
opts.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轴title
opts.yAxis.disabled          Boolean default false        不绘制Y轴
opts.series                  Array required        数据列表

数据列表每项结构定义

dataItem                      Object
dataItem.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,
 });
}

 
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
});

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‘
    }
});

 
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,
});

 
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
});

 
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
        }
    }
});

本人是自己查阅资料自己整理,希望对自己和有问题的你们都有帮助

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/m0_37805167/article/details/75160063

原文地址:https://www.cnblogs.com/xiaobai-y/p/9089157.html

时间: 2024-08-15 23:05:09

wx-charts 微信小程序图表插件的相关文章

微信小程序图表组件 wx-f2

摘自 杀个程序猿祭天  https://www.jianshu.com/p/6b9fe45f799f Github地址:https://github.com/antvis/wx-f2 AntV F2地址: AntV F2 微信小程序图表组件 wx-f2,源于 F2,专为移动而生 F2,专为移动而生的可视化解决方案,特为大家提供了微信小程序端版本,体积小巧,性能卓越,底层基于图形语法,可以提供非常丰富的图表类型. 可以使用微信扫描以下二维码先体验一番: image wx-f2 F2 的微信小程序版

自制微信小程序 提示插件 -- noticeUitis.js

/* noticeMsg.js by: FEer_llx 2016/06/09 */ var notice = { //用于计时器,判断动画事件结束时下一个动画事件才能执行 flag: true, //头部自动下拉隐藏提示效果 autoSlideDown: function (opt) { opt._this.animation.translateY(opt.changeVaule).step() opt._this.setData({ animation: opt._this.animatio

微信小程序-整理各种小程序源码和资料免费下载

微信小程序整理下载 [小程序源码]微信小程序-车源宝微信版 [小程序源码]小程序-微赞社区(论坛demo) [小程序源码]微信小程序-收支账单 [小程序工具]微信小程序-日历 [小程序源码]小程序-在线聊天功能 [小程序源码]微信小程序-大好商城(新增功能天气查询和2048游戏) [小程序源码]微信小程序-查询号码归属地 [小程序源码]微信小程序-备忘录2 [小程序源码]微信小程序-QQ音乐 [小程序源码]小程序-货币汇率 [小程序源码]微信小程序-大学图书馆 [小程序源码]小程序-积分商城 [

微信小程序开源项目库汇总

微信小程序开源项目库汇总,里面集合了OpenDigg 上的优质的微信小程序开源项目库,方便移动开发人员便捷的找到自己需要的项目工具等,感兴趣的可以到GitHub上给个star. UI组件 weui-wxss ★852 - 同微信原生视觉体验一致的基础样式库 Wa-UI ★122 - 针对微信小程序整合的一套UI库 wx-charts ★105 - 微信小程序图表工具 wemark ★85 - 微信小程序Markdown渲染库 WeZRender ★36 - 微信小程序Canvas增强组件 wet

微信小程序UI组件、开发框架、实用库

UI组件 weui-wxss ★852 - 同微信原生视觉体验一致的基础样式库 Wa-UI ★122 - 针对微信小程序整合的一套UI库 wx-charts ★105 - 微信小程序图表工具 wemark ★85 - 微信小程序Markdown渲染库 WeZRender ★36 - 微信小程序Canvas增强组件 wetoast ★21 - 仿照微信小程序提供的showToast功能 wxapp-charts ★20 - 微信小程序图表charts组件 WeiXinProject ★18 - 列

微信小程序学习指南

作者:初雪链接:https://www.zhihu.com/question/50907897/answer/128494332来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 微信小程序正式公测, 张小龙全面阐述小程序,定档1月9日上线(附90分钟演讲全文) ... 前言:新人第一坑,跳坑指南:修改后,必须保存:ctrl+S: 1:官方工具:https://mp.weixin.qq.com/debug/w ... tml?t=1476434678461 2:简易教

微信小程序框架集合

UI组件 weui-wxss ★852 - 同微信原生视觉体验一致的基础样式库 Wa-UI ★122 - 针对微信小程序整合的一套UI库 wx-charts ★105 - 微信小程序图表工具 wemark ★85 - 微信小程序Markdown渲染库 WeZRender ★36 - 微信小程序Canvas增强组件 wetoast ★21 - 仿照微信小程序提供的showToast功能 wxapp-charts ★20 - 微信小程序图表charts组件 WeiXinProject ★18 - 列

微信小程序源码下载(200多个)

微信小程序源码下载汇总,点击标题进入对应的微信小程序下载页面. 最新 demo源码(点击标题进入帖子下载) 描述 1 微信小程序 会议室预定小程序 微信小程序 会议室预定小程序**** 本内容被作者隐藏 **** 2 微信小程序-双人五子棋小游戏 微信小程序-双人五子棋小游戏**** 本内容被作者隐藏 **** 3 打卡签到小程序 用微信小程序实现的一个简单的打卡签到的小程序拒绝 4 微信小程序---左滑删除 微信小程序---左滑删除**** 本内容被作者隐藏 **** 5 一个借钱的记事本的微

分享一下微信小程序的实例【转】

wx-gesture-lock  微信小程序的手势密码 WXCustomSwitch 微信小程序自定义 Switch 组件模板 WeixinAppBdNovel 微信小程序demo:百度小说搜索 shitoujiandaobu 小程序:石头剪刀布(附代码说明) audiodemo 微信小程序开发之视频播放器 Video 弹幕 弹幕颜色自定义 star 微信小程序开发之五星评分 switchCity 微信小程序开发之城市选择器 城市切换 huadong_del  微信小程序滑动删除效果 jianh