new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Chart.js · all subjects

scales/category

10 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Category axis internal data format

Internally, the category scale uses label indices to represent positions.

Category axis label sources - global vs axis definition

When using global configuration, labels are drawn from chart data in this priority: if data.labels is defined, it is used; if data.xLabels is defined and the axis is horizontal, it is used; if data.yLabels is defined and the axis is vertical, it is used. Using both xLabels and yLabels together can create a chart that uses strings for both X and Y axes. Specifying any of these label settings defines the x-axis as type: 'category' if not defined otherwise. For fine-grained control, labels can be added as part of the category axis definition in options.scales, which does not apply global defaults.

Category axis global configuration example

To configure a category axis globally, define labels in the chart data object: let chart = new Chart(ctx, { type: ..., data: { labels: ['January', 'February', 'March', 'April', 'May', 'June'], datasets: ... } });

Category axis axis definition configuration example

To configure a category axis as part of axis definition, specify type and labels in options.scales: let chart = new Chart(ctx, { type: ..., data: ..., options: { scales: { x: { type: 'category', labels: ['January', 'February', 'March', 'April', 'May', 'June'] } } } });

Category axis configuration options table

Category axis specific options are configured in options.scales[scaleId]. The options are: min (string|number) - The minimum item to display; max (string|number) - The maximum item to display; labels (string[]|string[][]) - An array of labels to display, where individual labels can be an array of strings with each item rendered on a new line.

Category axis min and max configuration

For both min and max properties in a category axis, the value must be either a string that exists in the labels array or a numeric value representing the index of a label in that array. For example, setting min: 'March' displays only labels from 'March' onwards.

Category axis min-max example

Example showing how to restrict the displayed range of a category axis: let chart = new Chart(ctx, { type: 'line', data: { datasets: [{ data: [10, 20, 30, 40, 50, 60] }], labels: ['January', 'February', 'March', 'April', 'May', 'June'] }, options: { scales: { x: { min: 'March' } } } }); This displays only March through June on the x axis.

Category axis internal data format

The category axis, which is the default x-axis for line and bar charts, uses the index as its internal data format. To access the label value, use this.getLabelForValue(value).

Category scale internal format

The category scale uses integers as its internal format, where each integer represents an index in the labels array. When parsing is enabled, it can also parse string labels directly.

Category scale in stacked configuration

A category scale can be included in a stacked scales setup. The category scale uses the 'labels' property to define the category values (e.g., ['ON', 'OFF']). When stacking, the category scale must have offset set to true and be assigned a stack name and stackWeight like other scales.

Give your agent this brain