Categories &

Functions List

Class Definition: BarData

chartjs: BarData

One dataset of a bar chart.

A BarChart holds a BarData object for each of its datasets, whose properties set how Chart.js draws it.

Each property is documented on its own, as in help BarData.data.

See also: BarChart, Color, Fill

Source Code: BarData

The BarData class contains the following properties:

A Color object defining the color of the face of the bars. Default is empty, in which case and a color is assigned automatically by the Chart.js library.

A numeric scalar value. It defines the base value for the bar in data units along the value axis (the y-axis by default).

A numeric scalar value. It defines the percent, in the range [0-1], of the available width each bar should be within the category width. barPercentage = 1.0 will take the whole category width and put the bars right next to each other.

Either a numeric scalar or a character vector. When numeric, it defines the width of each bar in pixels, in which case barPercentage and categoryPercentage properties are ignored. If set to 'flex', the base sample widths are calculated automatically based on the previous and following samples so that they take the full available widths without overlap. Then, bars are sized using the barPercentage and categoryPercentage properties. There is no gap when the percentage options are 1. This mode generates bars with different widths when data are not evenly spaced. By default it is empty, in which case the base sample widths are calculated using the smallest interval that prevents bar overlapping, and bars are sized using barPercentage and categoryPercentage properties. This mode always generates bars equally sized.

A Color object defining the color of the border line of the bars. Default is empty, in which case a color is assigned automatically by the Chart.js library.

A boolean scalar or a character vector. This setting is used to avoid drawing any given border of each bar. As a boolean value, false does not skip any borders and true skips drawing all borders. As a character vector, it can take any of the following values: 'start', 'end', 'middle', 'bottom', 'left', 'top', and 'right'. 'middle' is only valid on stacked bars, in which case the borders between stacked bars are skipped.

A numeric scalar value defining the width of the each bar’s borders in pixels. Omitted borders as defined by the borderSkipped property are unaffected.

A numeric scalar value defining the corner radius of the each bar in pixels. Omitted borders as defined by the borderSkipped property are unaffected.

A numeric scalar value, which defines the percent, in the range [0-1], of the available width each category should be within the sample width.

A numeric scalar value defining the pixels to clip relative to the chart’s area. Positive value allows overflow, negative value clips that many pixels inside chartArea. Defaults to zero pixels.

A numeric vector assigned at construction of the BarData object. It cannot be empty.

A boolean scalar defining how the bars are grouped on the index axis (the x-axis by default). When true, all the datasets at same index value will be placed next to each other centering on that index value. When false, each bar is placed on its actual index-axis value.

A Color object defining the color of the face of each bar, when the mouse hovers over it. Default is empty, in which case the color is the same as in backgroundColor.

A Color object defining the color of the borders of each bar, when the mouse hovers over it. Default is empty, in which case the color is the same as in borderColor.

A numeric scalar value defining the width of the each bar’s borders in pixels, when the mouse hovers over it. Omitted borders as defined by the borderSkipped property are unaffected.

A numeric scalar value defining the corner radius of the each bar in pixels, when the mouse hovers over it. Omitted borders as defined by the borderSkipped property are unaffected.

A character vector defining the base axis of the dataset. 'x' defines a vertical bar chart (default) and 'y' defines a horizontal bar chart

Either a numeric scalar or a character vector. When numeric, it defines the amount to inflate the rectangulars used to draw the bars. This is useful for hiding artifacts between bars when barPercentage × categoryPercentage = 1. The default value is 'auto', which should work in most cases.

A character vector defining the label of the dataset which appears in the legend and tooltips. A chart shows no legend when none of its datasets has a label, and names a dataset without one by its position, such as "Dataset 2", when another has one.

A numeric scalar value defining the maximum thickness of the bars in pixels.

A numeric scalar value defining the minimum height of the bars in pixels.

A numeric scalar defining the order of the dataset, which affects order for stacking, tooltip and legend.

A boolean scalar. If true or empty (default), the null or undefined values in data will not be used for spacing calculations when determining bar size.

A character vector defining the ID of the group which this dataset belongs to (when stacked, each group will be a separate stack).

The BarData class offers the following public methods:

BarData: obj = BarData (data)

obj = BarData (data) returns a BarData object, in which data must be a nonempty numerical vector containing the bar heights of a single dataset. Constructing a BarData object always assigns the default property values, which can later be modified using dot notation syntax.

BarData: json = jsonstring (obj)

BarData: json = jsonstring (obj, mixed)

jsonstring (obj) returns a character vector, json, holding the dataset in JSON, as Chart.js reads it in the datasets of a chart.

jsonstring (obj, mixed) also writes the dataset’s chart type when mixed is true, as a chart mixing types needs.