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
Utils - Chart.js中文文档 - 笔下光年
网站首页
Utils
## 免责声明 Utils 文件包含 `chart.js` 示例页用于生成图表的多个助手函数。这些功能可能会发生变化,包括但不限于未经事先通知擅自更改。 因此,请不要在生产环境中依赖此文件。 ## Functions ```javascript import colorLib from '@kurkle/color'; import {DateTime} from 'luxon'; import 'chartjs-adapter-luxon'; import {valueOrDefault} from '../../dist/helpers.js'; // Adapted from http://indiegamr.com/generate-repeatable-random-numbers-in-js/ var _seed = Date.now(); export function srand(seed) { _seed = seed; } export function rand(min, max) { min = valueOrDefault(min, 0); max = valueOrDefault(max, 0); _seed = (_seed * 9301 + 49297) % 233280; return min + (_seed / 233280) * (max - min); } export function numbers(config) { var cfg = config || {}; var min = valueOrDefault(cfg.min, 0); var max = valueOrDefault(cfg.max, 100); var from = valueOrDefault(cfg.from, []); var count = valueOrDefault(cfg.count, 8); var decimals = valueOrDefault(cfg.decimals, 8); var continuity = valueOrDefault(cfg.continuity, 1); var dfactor = Math.pow(10, decimals) || 0; var data = []; var i, value; for (i = 0; i < count; ++i) { value = (from[i] || 0) + this.rand(min, max); if (this.rand() <= continuity) { data.push(Math.round(dfactor * value) / dfactor); } else { data.push(null); } } return data; } export function points(config) { const xs = this.numbers(config); const ys = this.numbers(config); return xs.map((x, i) => ({x, y: ys[i]})); } export function bubbles(config) { return this.points(config).map(pt => { pt.r = this.rand(config.rmin, config.rmax); return pt; }); } export function labels(config) { var cfg = config || {}; var min = cfg.min || 0; var max = cfg.max || 100; var count = cfg.count || 8; var step = (max - min) / count; var decimals = cfg.decimals || 8; var dfactor = Math.pow(10, decimals) || 0; var prefix = cfg.prefix || ''; var values = []; var i; for (i = min; i < max; i += step) { values.push(prefix + Math.round(dfactor * i) / dfactor); } return values; } const MONTHS = [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ]; export function months(config) { var cfg = config || {}; var count = cfg.count || 12; var section = cfg.section; var values = []; var i, value; for (i = 0; i < count; ++i) { value = MONTHS[Math.ceil(i) % 12]; values.push(value.substring(0, section)); } return values; } const COLORS = [ '#4dc9f6', '#f67019', '#f53794', '#537bc4', '#acc236', '#166a8f', '#00a950', '#58595b', '#8549ba' ]; export function color(index) { return COLORS[index % COLORS.length]; } export function transparentize(value, opacity) { var alpha = opacity === undefined ? 0.5 : 1 - opacity; return colorLib(value).alpha(alpha).rgbString(); } export const CHART_COLORS = { red: 'rgb(255, 99, 132)', orange: 'rgb(255, 159, 64)', yellow: 'rgb(255, 205, 86)', green: 'rgb(75, 192, 192)', blue: 'rgb(54, 162, 235)', purple: 'rgb(153, 102, 255)', grey: 'rgb(201, 203, 207)' }; const NAMED_COLORS = [ CHART_COLORS.red, CHART_COLORS.orange, CHART_COLORS.yellow, CHART_COLORS.green, CHART_COLORS.blue, CHART_COLORS.purple, CHART_COLORS.grey, ]; export function namedColor(index) { return NAMED_COLORS[index % NAMED_COLORS.length]; } export function newDate(days) { return DateTime.now().plus({days}).toJSDate(); } export function newDateString(days) { return DateTime.now().plus({days}).toISO(); } export function parseISODate(str) { return DateTime.fromISO(str); } ``` [File on github](https://github.com/chartjs/Chart.js/blob/master/docs/scripts/utils.js "File on github") ### 组件 一些示例引用组件对象。这是使用模块绑定器构建样本的产物。该组件对象的创建如下所示。如果 `chart.js` 作为浏览器脚本包含,则可以通过chart对象(即`chart.Tooltip`)访问这些项目。 ```javascript // Add Chart components needed in samples here. // Usable through `components[name]`. export {Tooltip} from '../../dist/chart.js'; ``` [File on github](https://github.com/chartjs/Chart.js/blob/master/docs/scripts/components.js "File on github")
上一篇:
Quadrants