A bar chart provides a way of showing data values represented as vertical bars.
Bar datasets are easy to create - just provide a dataset label and a list of floats
defaultBarFromData "Example Chart" [ 4, 8, 15, 16, 23, 42 ]When grouping datasets into a chart data object, the labels specified will be used as the bar chart categories:
dataset =
defaultBarFromData "Example Chart" [ 4, 8, 15, 16, 23, 42 ]
|> ChartData.BarData
data =
ChartData.dataFromLabels [ "One", "Two", "Three", "Four", "Five", "Six" ]
|> ChartData.addDataset datasetCreate a Bar dataset with just a label
Create a Bar dataset with a label and data
Set the data displayed by this dataset This is a list of floats, where each float is represented as a bar
Set the label for this dataset
Set whether this dataset should be hidden from the chart
Set the drawing order of the dataset This also affects stacking, tooltips, and legends
To stack bars, use setStack to assign each dataset to a stacking group. In this example, dataset1 and dataset2 will be stacked together:
dataset1 =
BarData.defaultBarFromData [ 10, 20, 30 ]
|> setStack "Stack 1"
dataset2 =
BarData.defaultBarFromData [ 5, 15, 25 ]
|> setStack "Stack 1"
dataset3 =
BarData.defaultBarFromData [ 20, 40, 30 ]
|> setStack "Stack 2"ID of the group, used for stacking datasets eg. two datasets with the same field for stack will be stacked together
See the Scale module for more information on custom axes
Which axis to use for indexing Set to XAxis for a vertical chart, set to YAxis for a horizontal chart
The ID of the X axis to plot the dataset on
The ID of the Y axis to plot the dataset on
0-1 percentage of the available width each bar should be within the category width.
Manually force the width (in pixels) of each bar
Percent (0-1) of the available width each category should be within the sample width.
Max bar thickness, in pixels If set, bars will not be thicker than this value
Minimum bar length, in pixels If set, bars will not be shorter than this value
Fill color of the bar
Border color of the bar
Border radius for each bar
Which edge to skip drawing border for One of: 'bottom' 'left' 'top' 'right'
Stroke width of the bar in pixels
Fill color of the bar when hovered
Border color of the bar when hovered
Border width of the bar when hovered
For further information on these properties, see https://www.chartjs.org/docs/latest/charts/bar.html
You should not use the dataset type directly Instead use the updater pipeline functions: