Chart.js
入门指南
入门
安装
集成
分步指南
概览
可访问性(Accessibility)
颜色(Colors)
数据结构(Data structures)
字体(Fonts)
选项(Options)
内边距(Padding)
性能(Performance)
图表配置
配置(Configuration)
动画(Animations)
画布背景(Canvas background)
数据抽取(Data Decimation)
设备像素比率(Device Pixel Ratio)
通用配置(Elements)
互动(Interactions)
布局(Layout)
图例(Legend)
本地化(Locale)
响应式图表(Responsive Charts)
副标题(Subtitle)
标题(Title)
提示(Tooltip)
Charts
面积图(Area Chart)
柱状/条形图(Bar Chart)
气泡图(Bubble Chart)
环形&饼图(Doughnut and Pie Charts)
折线图(Line Chart)
混合图表(Mixed Chart Types)
极地图(Polar Area Chart)
雷达图(Radar Chart)
离散图(Scatter Chart)
坐标轴
轴(Axes)
笛卡尔坐标(Cartesian)
笛卡尔坐标轴(Cartesian Axes)
分类轴(Category Axis)
线性轴(Linear Axis)
对数轴(Logarithmic Axis)
时间笛卡尔轴(Time Cartesian Axis)
时间序列轴(Time Series Axis)
径向(Radial)
径向轴(Radial Axes)
线性径向轴(Linear Radial Axis)
标签轴(Labelling Axes)
样式(Styling)
开发者
开发者(Developers)
Chart.js API
坐标轴扩展
图表扩展
贡献
插件
发布扩展
更新 Charts
迁移
4.x迁移指南
3.x迁移指南
示例
Chart.js Samples
Bar Charts
Bar Chart Border Radius
Floating Bars
Horizontal Bar Chart
Stacked Bar Chart
Stacked Bar Chart with Groups
Vertical Bar Chart
Line Charts
Interpolation Modes
Line Chart
Multi Axis Line Chart
Point Styling
Line Segment Styling
Stepped Line Charts
Line Styling
Other charts
Bubble
Combo bar/line
Doughnut
Multi Series Pie
Pie
Polar area
Polar area centered point labels
Radar
Radar skip points
Scatter
Scatter - Multi axis
Stacked bar/line
Area charts
Line Chart Boundaries
Line Chart Datasets
Line Chart drawTime
Line Chart Stacked
Radar Chart Stacked
Scales
Linear Scale - Min-Max
Linear Scale - Suggested Min-Max
Linear Scale - Step Size
Log Scale
Stacked Linear / Category
Time Scale
Time Scale - Max Span
Time Scale - Combo Chart
Scale Options
Center Positioning
Grid Configuration
Tick Configuration
Title Configuration
Legend
Events
HTML Legend
Point Style
Position
Alignment and Title Position
Title
Alignment
Subtitle
Basic
Tooltip
Custom Tooltip Content
External HTML Tooltip
Interaction Modes
Point Style
Position
Scriptable Options
Bar Chart
Bubble Chart
Line Chart
Pie Chart
Polar Area Chart
Radar Chart
Animations
Delay
Drop
Loop
Progressive Line
Progressive Line With Easing
Advanced
Data Decimation
Derived Axis Type
Derived Chart Type
Linear Gradient
Programmatic Event Triggers
Animation Progress Bar
Radial Gradient
Plugins
Chart Area Border
Doughnut Empty State
Quadrants
Utils
动画(Animations) - Chart.js中文文档 - 笔下光年
网站首页
动画(Animations)
Chart.js animates charts out of the box. A number of options are provided to configure how the animation looks and how long it takes. <iframe src="http://example.itshubao.com/inexample/322.html" width="100%" height="920px" frameborder="0" scrolling="no"></iframe> ## Animation configuration Animation configuration consists of 3 keys. | Name | Type | Details | |-------------|--------|-------------| | animation | object | animation | | animations | object | animations | | transitions | object | transitions | These keys can be configured in following paths: - `` - chart options - datasets[type] - dataset type options - overrides[type] - chart type options These paths are valid under defaults for global configuration and options for instance configuration. ## animation The default configuration is defined here: [core.animations.js](https://github.com/chartjs/Chart.js/blob/master/src/core/core.animations.js "core.animations.js") Namespace: `options.animation` | Name | Type | Default | Description | |----------|---------|----------------|------------------------------------------------| | duration | number | 1000 | The number of milliseconds an animation takes. | | easing | string | `'easeOutQuart'` | Easing function to use. more... | | delay | number | undefined | Delay before starting the animations. | | loop | boolean | undefined | If set to true, the animations loop endlessly. | These defaults can be overridden in options.animation or dataset.animation and tooltip.animation. These keys are also Scriptable. ## animations Animations options configures which element properties are animated and how. In addition to the main animation configuration, the following options are available: Namespace: `options.animations[animation]` | Name | Type | Default | Description | |------------|------------|-----------------|-----------| | properties | `string[]` | key | The property names this configuration applies to. Defaults to the key name of this object. | | type | `string` | typeof property | Type of property, determines the interpolator used. Possible values: 'number', 'color' and 'boolean'. Only really needed for 'color', because typeof does not get that right. | | from | number | Color | boolean | undefined | Start value for the animation. Current value is used when undefined | | to | number | Color | boolean | undefined | End value for the animation. Updated value is used when undefined | | fn | <T>(from: T, to: T, factor: number) => T; | undefined | Optional custom interpolator, instead of using a predefined interpolator from type | ### Default animations | Name | Option | Value | |---------|------------|--------| | numbers | properties | ['x', 'y', 'borderWidth', 'radius', 'tension'] | | numbers | type | 'number' | | colors | properties | ['color', 'borderColor', 'backgroundColor'] | | colors | type | 'color' | > Note These default animations are overridden by most of the dataset controllers. ## transitions The core transitions are 'active', 'hide', 'reset', 'resize', 'show'. A custom transition can be used by passing a custom mode to update. Transition extends the main animation configuration and animations configuration. ### Default transitions Namespace: options.transitions[mode] | Mode | Option | Value | Description | |----------|----------------|-----------------|--------------| | 'active' | `animation.duration` | 400 | Override default duration to 400ms for hover animations | | 'resize' | `animation.duration` | 0 | Override default duration to 0ms (= no animation) for resize | | 'show' | `animations.colors` | `{ type: 'color', properties: ['borderColor', 'backgroundColor'], from: 'transparent' }` | Colors are faded in from transparent when dataset is shown using legend / api. | | 'show' | `animations.visible` | `{ type: 'boolean', duration: 0 }` | Dataset visibility is immediately changed to true so the color transition from transparent is visible. | | 'hide' | `animations.colors` | `{ type: 'color', properties: ['borderColor', 'backgroundColor'], to: 'transparent' }` | Colors are faded to transparent when dataset id hidden using legend / api. | | 'hide' | `animations.visible` | `{ type: 'boolean', easing: 'easeInExpo' }` | Visibility is changed to false at a very late phase of animation | ## Disabling animation To disable an animation configuration, the animation node must be set to false, with the exception for animation modes which can be disabled by setting the duration to 0. ```javascript chart.options.animation = false; // disables all animations chart.options.animations.colors = false; // disables animation defined by the collection of 'colors' properties chart.options.animations.x = false; // disables animation defined by the 'x' property chart.options.transitions.active.animation.duration = 0; // disables the animation for 'active' mode ``` ## Easing Available options are: - 'linear' - 'easeInQuad' - 'easeOutQuad' - 'easeInOutQuad' - 'easeInCubic' - 'easeOutCubic' - 'easeInOutCubic' - 'easeInQuart' - 'easeOutQuart' - 'easeInOutQuart' - 'easeInQuint' - 'easeOutQuint' - 'easeInOutQuint' - 'easeInSine' - 'easeOutSine' - 'easeInOutSine' - 'easeInExpo' - 'easeOutExpo' - 'easeInOutExpo' - 'easeInCirc' - 'easeOutCirc' - 'easeInOutCirc' - 'easeInElastic' - 'easeOutElastic' - 'easeInOutElastic' - 'easeInBack' - 'easeOutBack' - 'easeInOutBack' - 'easeInBounce' - 'easeOutBounce' - 'easeInOutBounce' See [Robert Penner's easing equations](http://robertpenner.com/easing/ "Robert Penner's easing equations") . ## Animation Callbacks The animation configuration provides callbacks which are useful for synchronizing an external draw to the chart animation. The callbacks can be set only at main animation configuration. Namespace: options.animation | Name | Type | Default | Description | |------------|----------|---------|----------| | onProgress | function | null | Callback called on each step of an animation. | | onComplete | function | null | Callback called when all animations are completed. | The callback is passed the following object: ```javascript { // Chart object chart: Chart, // Number of animations still in progress currentStep: number, // `true` for the initial animation of the chart initial: boolean, // Total number of animations at the start of current animation numSteps: number, } ``` The following example fills a progress bar during the chart animation. ```javascript const chart = new Chart(ctx, { type: 'line', data: data, options: { animation: { onProgress: function(animation) { progress.value = animation.currentStep / animation.numSteps; } } } }); ``` Another example usage of these callbacks can be found in this progress bar sample. which displays a progress bar showing how far along the animation is.
上一篇:
配置(Configuration)
下一篇:
画布背景(Canvas background)