mirror of
https://github.com/chartjs/Chart.js.git
synced 2026-03-14 12:16:52 +01:00
[types][beta-5] fixed stacked scale, changed default type for data.labels (#8001)
* Scale: added the stacked property for all scales * interfaces: generic type LABEL can be string, Date, etc. * controllers: stack can be used for all types of dataset * docs/data-structures: added general dataset properties Co-authored-by: Sergey Khomushin <sergey@placer.io>
This commit is contained in:
@@ -46,7 +46,28 @@ options: {
|
||||
}
|
||||
```
|
||||
|
||||
### `parsing` can also be specified per dataset
|
||||
## Object
|
||||
|
||||
```javascript
|
||||
data: {
|
||||
January: 10,
|
||||
February: 20
|
||||
}
|
||||
```
|
||||
|
||||
In this mode, property name is used for `index` scale and value for `value` scale. For vertical charts, index scale is `x` and value scale is `y`.
|
||||
|
||||
## Dataset Configuration
|
||||
|
||||
| Name | Type | Description
|
||||
| ---- | ---- | -----------
|
||||
| `label` | `string` | The label for the dataset which appears in the legend and tooltips.
|
||||
| `clip` | <code>number|object</code> | How to clip relative to chartArea. Positive value allows overflow, negative value clips that many pixels inside chartArea. 0 = clip at chartArea. Clipping can also be configured per side: clip: {left: 5, top: false, right: -2, bottom: 0}
|
||||
| `order` | `number` | The drawing order of dataset. Also affects order for stacking, tooltip and legend.
|
||||
| `stack` | `string` | The ID of the group to which this dataset belongs to (when stacked, each group will be a separate stack).
|
||||
| `parsing` | <code>boolean|object</code> | How to parse the dataset. The parsing can be disabled by specifying parsing: false at chart options or dataset. If parsing is disabled, data must be sorted and in the formats the associated chart type and scales use internally.
|
||||
|
||||
### parsing
|
||||
|
||||
```javascript
|
||||
const data = [{x: 'Jan', net: 100, cogs: 50, gm: 50}, {x: 'Feb', net: 120, cogs: 55, gm: 75}];
|
||||
@@ -76,14 +97,3 @@ const cfg = {
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
## Object
|
||||
|
||||
```javascript
|
||||
data: {
|
||||
January: 10,
|
||||
February: 20
|
||||
}
|
||||
```
|
||||
|
||||
In this mode, property name is used for `index` scale and value for `value` scale. For vertical charts, index scale is `x` and value scale is `y`.
|
||||
|
||||
10
types/controllers/index.d.ts
vendored
10
types/controllers/index.d.ts
vendored
@@ -26,6 +26,11 @@ export interface IControllerDatasetOptions {
|
||||
* The drawing order of dataset. Also affects order for stacking, tooltip and legend.
|
||||
*/
|
||||
order: number;
|
||||
|
||||
/**
|
||||
* The ID of the group to which this dataset belongs to (when stacked, each group will be a separate stack).
|
||||
*/
|
||||
stack: string;
|
||||
}
|
||||
|
||||
export interface IBarControllerDatasetOptions
|
||||
@@ -71,11 +76,6 @@ export interface IBarControllerDatasetOptions
|
||||
* Set this to ensure that bars have a minimum length in pixels.
|
||||
*/
|
||||
minBarLength: number;
|
||||
|
||||
/**
|
||||
* The ID of the group to which this dataset belongs to (when stacked, each group will be a separate stack).
|
||||
*/
|
||||
stack: string;
|
||||
}
|
||||
|
||||
export interface IBarControllerChartOptions {
|
||||
|
||||
2
types/interfaces.d.ts
vendored
2
types/interfaces.d.ts
vendored
@@ -176,7 +176,7 @@ export type IChartDataset<
|
||||
export interface IChartData<
|
||||
TYPE extends IChartType = IChartType,
|
||||
DATA extends unknown[] = DefaultDataPoint<TYPE>,
|
||||
LABEL = string
|
||||
LABEL = unknown
|
||||
> {
|
||||
labels: LABEL[];
|
||||
datasets: IChartDataset<TYPE, DATA>[];
|
||||
|
||||
8
types/scales/index.d.ts
vendored
8
types/scales/index.d.ts
vendored
@@ -122,6 +122,12 @@ export interface ICartesianScaleOptions extends ICoreScaleOptions {
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* If true, data will be comprised between datasets of data
|
||||
* @default false
|
||||
*/
|
||||
stacked?: boolean;
|
||||
|
||||
ticks: ITickOptions & {
|
||||
/**
|
||||
* The number of ticks to examine when deciding how many labels will fit. Setting a smaller value will be faster, but may be less accurate when there is large variability in label length.
|
||||
@@ -193,7 +199,6 @@ export const CategoryScale: IChartComponent & {
|
||||
};
|
||||
|
||||
export type ILinearScaleOptions = ICartesianScaleOptions & {
|
||||
stacked?: boolean;
|
||||
|
||||
/**
|
||||
* if true, scale will include 0 if it is not already included.
|
||||
@@ -243,7 +248,6 @@ export const LinearScale: IChartComponent & {
|
||||
};
|
||||
|
||||
export type ILogarithmicScaleOptions = ICartesianScaleOptions & {
|
||||
stacked?: boolean;
|
||||
|
||||
/**
|
||||
* Adjustment used when calculating the maximum data value.
|
||||
|
||||
Reference in New Issue
Block a user