| commit | author | age | ||
| 83c3f6 | 1 | # Linear Cartesian Axis |
| SP | 2 | |
| 3 | The linear scale is use to chart numerical data. It can be placed on either the x or y axis. The scatter chart type automatically configures a line chart to use one of these scales for the x axis. As the name suggests, linear interpolation is used to determine where a value lies on the axis. | |
| 4 | ||
| 5 | ## Tick Configuration Options | |
| 6 | ||
| 7 | The following options are provided by the linear scale. They are all located in the `ticks` sub options. These options extend the [common tick configuration](README.md#tick-configuration). | |
| 8 | ||
| 9 | | Name | Type | Default | Description | |
| 10 | | -----| ---- | --------| ----------- | |
| 11 | | `beginAtZero` | `Boolean` | | if true, scale will include 0 if it is not already included. | |
| 12 | | `min` | `Number` | | User defined minimum number for the scale, overrides minimum value from data. [more...](#axis-range-settings) | |
| 13 | | `max` | `Number` | | User defined maximum number for the scale, overrides maximum value from data. [more...](#axis-range-settings) | |
| 14 | | `maxTicksLimit` | `Number` | `11` | Maximum number of ticks and gridlines to show. | |
| 15 | | `precision` | `Number` | | if defined and `stepSize` is not specified, the step size will be rounded to this many decimal places. | |
| 16 | | `stepSize` | `Number` | | User defined fixed step size for the scale. [more...](#step-size) | |
| 17 | | `suggestedMax` | `Number` | | Adjustment used when calculating the maximum data value. [more...](#axis-range-settings) | |
| 18 | | `suggestedMin` | `Number` | | Adjustment used when calculating the minimum data value. [more...](#axis-range-settings) | |
| 19 | ||
| 20 | ## Axis Range Settings | |
| 21 | ||
| 22 | Given the number of axis range settings, it is important to understand how they all interact with each other. | |
| 23 | ||
| 24 | 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. | |
| 25 | ||
| 26 | ```javascript | |
| 27 | let minDataValue = Math.min(mostNegativeValue, options.ticks.suggestedMin); | |
| 28 | let maxDataValue = Math.max(mostPositiveValue, options.ticks.suggestedMax); | |
| 29 | ``` | |
| 30 | ||
| 31 | 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. | |
| 32 | ||
| 33 | ```javascript | |
| 34 | let chart = new Chart(ctx, { | |
| 35 | type: 'line', | |
| 36 | data: { | |
| 37 | datasets: [{ | |
| 38 | label: 'First dataset', | |
| 39 | data: [0, 20, 40, 50] | |
| 40 | }], | |
| 41 | labels: ['January', 'February', 'March', 'April'] | |
| 42 | }, | |
| 43 | options: { | |
| 44 | scales: { | |
| 45 | yAxes: [{ | |
| 46 | ticks: { | |
| 47 | suggestedMin: 50, | |
| 48 | suggestedMax: 100 | |
| 49 | } | |
| 50 | }] | |
| 51 | } | |
| 52 | } | |
| 53 | }); | |
| 54 | ``` | |
| 55 | ||
| 56 | 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. | |
| 57 | ||
| 58 | ## Step Size | |
| 59 | If set, the scale ticks will be enumerated by multiple of stepSize, having one tick per increment. If not set, the ticks are labeled automatically using the nice numbers algorithm. | |
| 60 | ||
| 61 | This example sets up a chart with a y axis that creates ticks at `0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5`. | |
| 62 | ||
| 63 | ```javascript | |
| 64 | let options = { | |
| 65 | scales: { | |
| 66 | yAxes: [{ | |
| 67 | ticks: { | |
| 68 | max: 5, | |
| 69 | min: 0, | |
| 70 | stepSize: 0.5 | |
| 71 | } | |
| 72 | }] | |
| 73 | } | |
| 74 | }; | |
| 75 | ``` | |