anichart.js 使用笔记

anichart.js 是一款将数据转化为动态柱状图/线性图的 js/ts 工具,可导出视频。

github: https://github.com/Jannchie/anichart.js

中文使用指南:https://github.com/Jannchie/anichart.js/blob/main/README-CN.md

docs 目录中有更详细的使用方法(英文)。

在线演示:https://xoyozo.net/Demo/BarGraph


目前 release 版本 3.0.0。


这里有一点常用设置示例:https://codesandbox.io/s/anichart-2x-m3xbz?file=/main.js


设置画布尺寸

stage.canvas.width = 1000;
stage.canvas.height = 500;

重设尺寸不会重新计算内部元素的大小和位置,因此对响应式布局不太友好。


配置柱状图

示例:

const barChart = new ani.BarChart({
    dy: 2, // 文字下沉
    imageField: 'logo', // 图标字段名
    itemCount: 16, // 最多显示条数
    dateFormat: '%Y年%-m月', // 日期格式
    barGap: 10, // 柱条间距
    barInfoFormat: () => '', // 隐藏柱条上的文字
});
stage.addChild(barChart);


循环播放

setInterval(function () {
    if (!stage.playing) {
        stage.sec = 0;
        stage.play();
    }
}, 1000);


xoyozo 10 个月前
转载请注明出处
云服务器 精选特惠
可能相关的内容