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
轴(Axes) - Chart.js中文文档 - 笔下光年
网站首页
轴(Axes)
Axes are an integral part of a chart. They are used to determine how data maps to a pixel value on the chart. In a cartesian chart, there is 1 or more X-axis and 1 or more Y-axis to map points onto the 2-dimensional canvas. These axes are known as 'cartesian axes'. In a radial chart, such as a radar chart or a polar area chart, there is a single axis that maps points in the angular and radial directions. These are known as 'radial axes'. Scales in Chart.js >v2.0 are significantly more powerful, but also different than those of v1.0. - Multiple X & Y axes are supported. - A built-in label auto-skip feature detects would-be overlapping ticks and labels and removes every nth label to keep things displaying normally. - Scale titles are supported. - New scale types can be extended without writing an entirely new chart type. ## Default scales The default scaleId's for carterian charts are 'x' and 'y'. For radial charts: 'r'. Each dataset is mapped to a scale for each axis (x, y or r) it requires. The scaleId's that a dataset is mapped to, is determined by the xAxisID, yAxisID or rAxisID. If the ID for an axis is not specified, first scale for that axis is used. If no scale for an axis is found, a new scale is created. Some examples: The following chart will have 'x' and 'y' scales: ```javascript let chart = new Chart(ctx, { type: 'line' }); ``` The following chart will have scales 'x' and 'myScale': ```javascript let chart = new Chart(ctx, { type: 'bar', data: { datasets: [{ data: [1, 2, 3] }] }, options: { scales: { myScale: { type: 'logarithmic', position: 'right', // `axis` is determined by the position as `'y'` } } } }); ``` The following chart will have scales 'xAxis' and 'yAxis': ```javascript let chart = new Chart(ctx, { type: 'bar', data: { datasets: [{ yAxisID: 'yAxis' }] }, options: { scales: { xAxis: { // The axis for this scale is determined from the first letter of the id as `'x'` // It is recommended to specify `position` and / or `axis` explicitly. type: 'time', } } } }); ``` The following chart will have 'r' scale: ```javascript let chart = new Chart(ctx, { type: 'radar' }); ``` The following chart will have 'myScale' scale: ```javascript let chart = new Chart(ctx, { type: 'radar', scales: { myScale: { axis: 'r' } } }); ``` ## Common Configuration > Note These are only the common options supported by all axes. Please see specific axis documentation for all of the available options for that axis. ### Common options to all axes Namespace: options.scales[scaleId] | Name | Type | Default | Description | |-----------------|----------------|-----------------------|------------------| | type | string | | Type of scale being employed. Custom scales can be created and registered with a string key. This allows changing the type of an axis for a chart. | | alignToPixels | boolean | false | Align pixel values to device pixels. | | backgroundColor | Color | | Background color of the scale area. | | border | object | | Border configuration. more... | | display | boolean | string | true | Controls the axis global visibility (visible when true, hidden when false). When display: 'auto', the axis is visible only if at least one associated dataset is visible. | | grid | object | | Grid line configuration. more... | | min | number | | User defined minimum number for the scale, overrides minimum value from data. more... | | max | number | | User defined maximum number for the scale, overrides maximum value from data. more... | | reverse | boolean | false | Reverse the scale. | | stacked | boolean | string | false | Should the data be stacked. more... | | suggestedMax | number | | Adjustment used when calculating the maximum data value. more... | | suggestedMin | number | | Adjustment used when calculating the minimum data value. more... | | ticks | object | | Tick configuration. more... | | weight | number | 0 | The weight used to sort the axis. Higher weights are further away from the chart area. | ## Tick Configuration > Note These are only the common tick options supported by all axes. Please see specific axis documentation for all of the available tick options for that axis. ### Common tick options to all axes Namespace: options.scales[scaleId].ticks | Name | Type | Scriptable | Default | Description | |-------------------|----------|-----------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------| | backdropColor | Color | Yes | 'rgba(255, 255, 255, 0.75)' | Color of label backdrops. | | backdropPadding | Padding | | 2 | Padding of label backdrop. | | callback | function | | | Returns the string representation of the tick value as it should be displayed on the chart. See callback. | | display | boolean | | true | If true, show tick labels. | | color | Color | Yes | Chart.defaults.color | Color of ticks. | | font | Font | Yes | Chart.defaults.font | See Fonts | | major | object | | {} | Major ticks configuration. | | padding | number | | 3 | Sets the offset of the tick labels from the axis | | showLabelBackdrop | boolean | Yes | true for radial scale, false otherwise | If true, draw a background behind the tick labels. | | textStrokeColor | Color | Yes | `` | The color of the stroke around the text. | | textStrokeWidth | number | Yes | 0 | Stroke width around the text. | | z | number | | 0 | z-index of tick layer. Useful when ticks are drawn on chart area. Values <= 0 are drawn under datasets, > 0 on top. | ## Axis Range Settings Given the number of axis range settings, it is important to understand how they all interact with each other. The suggestedMax and suggestedMin settings only change the data values that are used to scale the axis. These are useful for extending the range of the axis while maintaining the auto fit behaviour. ```javascript let minDataValue = Math.min(mostNegativeValue, options.suggestedMin); let maxDataValue = Math.max(mostPositiveValue, options.suggestedMax); ``` In this example, the largest positive value is 50, but the data maximum is expanded out to 100. However, because the lowest data value is below the suggestedMin setting, it is ignored. ```javascript let chart = new Chart(ctx, { type: 'line', data: { datasets: [{ label: 'First dataset', data: [0, 20, 40, 50] }], labels: ['January', 'February', 'March', 'April'] }, options: { scales: { y: { suggestedMin: 50, suggestedMax: 100 } } } }); ``` In contrast to the suggested* settings, the min and max settings set explicit ends to the axes. When these are set, some data points may not be visible. ## Stacking By default data is not stacked. If the stacked option of the value scale (y-axis on horizontal chart) is true, positive and negative values are stacked separately. Additionally a stack option can be defined per dataset to further divide into stack groups more.... For some charts, you might want to stack positive and negative values together. That can be achieved by specifying stacked: 'single'. ## Callbacks There are a number of config callbacks that can be used to change parameters in the scale at different points in the update process. The options are supplied at the top level of the axis options. Namespace: options.scales[scaleId] | Name | Arguments | Description | |------------------------------|-----------|-------------------------------------------------------------------------| | beforeUpdate | axis | Callback called before the update process starts. | | beforeSetDimensions | axis | Callback that runs before dimensions are set. | | afterSetDimensions | axis | Callback that runs after dimensions are set. | | beforeDataLimits | axis | Callback that runs before data limits are determined. | | afterDataLimits | axis | Callback that runs after data limits are determined. | | beforeBuildTicks | axis | Callback that runs before ticks are created. | | afterBuildTicks | axis | Callback that runs after ticks are created. Useful for filtering ticks. | | beforeTickToLabelConversion | axis | Callback that runs before ticks are converted into strings. | | afterTickToLabelConversion | axis | Callback that runs after ticks are converted into strings. | | beforeCalculateLabelRotation | axis | Callback that runs before tick rotation is determined. | | afterCalculateLabelRotation | axis | Callback that runs after tick rotation is determined. | | beforeFit | axis | Callback that runs before the scale fits to the canvas. | | afterFit | axis | Callback that runs after the scale fits to the canvas. | | afterUpdate | axis | Callback that runs at the end of the update process. | ### Updating Axis Defaults The default configuration for a scale can be easily changed. All you need to do is set the new options to Chart.defaults.scales[type]. For example, to set the minimum value of 0 for all linear scales, you would do the following. Any linear scales created after this time would now have a minimum of 0. ```javascript Chart.defaults.scales.linear.min = 0; ``` ## Creating New Axes To create a new axis, see the developer docs.
上一篇:
坐标轴
下一篇:
笛卡尔坐标(Cartesian)