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
图表扩展 - Chart.js中文文档 - 笔下光年
网站首页
图表扩展
Chart.js 2.0 introduced the concept of controllers for each dataset. Like scales, new controllers can be written as needed. ```javascript class MyType extends Chart.DatasetController { } Chart.register(MyType); // Now we can create a new instance of our chart, using the Chart.js API new Chart(ctx, { // this is the string the constructor was registered at, ie Chart.controllers.MyType type: 'MyType', data: data, options: options }); ``` ## Dataset Controller Interface Dataset controllers must implement the following interface. ```javascript { // Defaults for charts of this type defaults: { // If set to `false` or `null`, no dataset level element is created. // If set to a string, this is the type of element to create for the dataset. // For example, a line create needs to create a line element so this is the string 'line' datasetElementType: string | null | false, // If set to `false` or `null`, no elements are created for each data value. // If set to a string, this is the type of element to create for each data value. // For example, a line create needs to create a point element so this is the string 'point' dataElementType: string | null | false, } // ID of the controller id: string; // Update the elements in response to new data // @param mode : update mode, core calls this method using any of `'active'`, `'hide'`, `'reset'`, `'resize'`, `'show'` or `undefined` update: function(mode) {} } ``` The following methods may optionally be overridden by derived dataset controllers. ```javascript { // Draw the representation of the dataset. The base implementation works in most cases, and an example of a derived version // can be found in the line controller draw: function() {}, // Initializes the controller initialize: function() {}, // Ensures that the dataset represented by this controller is linked to a scale. Overridden to helpers.noop in the polar area and doughnut controllers as these // chart types using a single scale linkScales: function() {}, // Parse the data into the controller meta data. The default implementation will work for cartesian parsing, but an example of an overridden // version can be found in the doughnut controller parse: function(start, count) {}, } ``` ## Extending Existing Chart Types Extending or replacing an existing controller type is easy. Simply replace the constructor for one of the built in types with your own. The built in controller types are: - BarController - BubbleController - DoughnutController - LineController - PieController - PolarAreaController - RadarController - ScatterController These controllers are also available in the UMD package, directly under Chart. Eg: Chart.BarController. For example, to derive a new chart type that extends from a bubble chart, you would do the following. ```javascript import {BubbleController} from 'chart.js'; class Custom extends BubbleController { draw() { // Call bubble controller method to draw all the points super.draw(arguments); // Now we can do some custom drawing for this dataset. Here we'll draw a red box around the first point in each dataset const meta = this.getMeta(); const pt0 = meta.data[0]; const {x, y} = pt0.getProps(['x', 'y']); const {radius} = pt0.options; const ctx = this.chart.ctx; ctx.save(); ctx.strokeStyle = 'red'; ctx.lineWidth = 1; ctx.strokeRect(x - radius, y - radius, 2 * radius, 2 * radius); ctx.restore(); } }; Custom.id = 'derivedBubble'; Custom.defaults = BubbleController.defaults; // Stores the controller so that the chart initialization routine can look it up Chart.register(Custom); // Now we can create and use our new chart type new Chart(ctx, { type: 'derivedBubble', data: data, options: options }); ``` ## TypeScript Typings If you want your new chart type to be statically typed, you must provide a .d.ts TypeScript declaration file. Chart.js provides a way to augment built-in types with user-defined ones, by using the concept of "declaration merging". When adding a new chart type, ChartTypeRegistry must contain the declarations for the new type, either by extending an existing entry in ChartTypeRegistry or by creating a new one. For example, to provide typings for a new chart type that extends from a bubble chart, you would add a .d.ts containing: ```javascript import { ChartTypeRegistry } from 'chart.js'; declare module 'chart.js' { interface ChartTypeRegistry { derivedBubble: ChartTypeRegistry['bubble'] } } ```
上一篇:
坐标轴扩展
下一篇:
贡献