Recommend this page to a friend! |
Classes of Jorge Castro | Gentelella BladeOne | vendors/chart.js/docs/04-Bar-Chart.md | Download |
|
Downloadtitle: Bar Chart anchor: bar-chartIntroductionA bar chart is a way of showing data as bars. It is sometimes used to show trend data, and the comparison of multiple data sets side by side. <div class="canvas-holder">
</div> Example Usage
Or if you want horizontal bars.
Data StructureThe following options can be included in a bar chart dataset to configure options for that specific dataset. Some properties can be specified as an array. If these are set to an array value, the first value applies to the first bar, the second value to the second bar, and so on. Property | Type | Usage
--- | --- | ---
data | An example data object using these attributes is shown below.
The bar chart has the a very similar data structure to the line chart, and has an array of datasets, each with colours and an array of data. We have an array of labels too for display. In the example, we are showing the same data as the previous line chart example. Chart OptionsThese are the customisation options specific to Bar charts. These options are merged with the global chart configuration options, and form the options of the chart. The default options for bar chart are defined in Name | Type | Default | Description
--- |:---:| --- | ---
hover.mode | String | "label" | Label's hover mode. "label" is used since the x axis displays data by the index in the dataset.
scales | Object | - | -
scales.xAxes | Array | | The bar chart officially supports only 1 x-axis but uses an array to keep the API consistent. Use a scatter chart if you need multiple x axes.
Options for xAxes | | |
type | String | "Category" | As defined in Scales.
display | Boolean | true | If true, show the scale.
id | String | "x-axis-0" | Id of the axis so that data can bind to it
stacked | Boolean | false | If true, bars are stacked on the x-axis
categoryPercentage | Number | 0.8 | Percent (0-1) of the available width (the space between the gridlines for small datasets) for each data-point to use for the bars. Read More
barPercentage | Number | 0.9 | Percent (0-1) of the available width each bar should be within the category percentage. 1.0 will take the whole category width and put the bars right next to each other. Read More
gridLines | Object | See Scales |
gridLines.offsetGridLines | Boolean | true | If true, the bars for a particular data point fall between the grid lines. If false, the grid line will go right down the middle of the bars.
| | |
scales.yAxes | Array | You can override these for your For example, we could have a bar chart without a stroke on each bar by doing the following:
We can also change these defaults values for each Bar type that is created, this object is available at The default options for horizontal bar charts are defined in Name | Type | Default | Description --- |:---:| --- | --- Options for xAxes | | | position | String | "bottom" | Options for yAxes | | | position | String | "left" | barPercentage vs categoryPercentageThe following shows the relationship between the bar percentage option and the category percentage option.
|