Class

Barchart

TimeCharts~Barchart(element, paramsopt)

Creates a bar chart

Constructor

new Barchart(element, paramsopt)

Constructs a bar chart
Parameters:
Name Type Attributes Default Description
element string css query selector of the container dom element into which the chart is placed.
params Object <optional>
options
barSize Object <optional>
25 the size of a bar in px.
data Array.<Object> <optional>
the data to be displayed. A list of bars that make up the bar chart.
data[].label string <optional>
the labels underneath the bar.
data[].datasets Array.<Object> <optional>
each dataset represents one "block" of a bar.
data[].datasets[].value number the value of the block.
data[].datasets[].title string <optional>
the title of the block.
data[].datasets[].color string <optional>
the color of the block.
max number | string <optional>
'relative' the max value of the chart.
padding Object <optional>
padding in all directions of the chart.
padding.top number | string <optional>
top padding for the chart.
padding.right number | string <optional>
right padding for the chart.
padding.bottom number | string <optional>
bottom padding for the chart.
padding.left number | string <optional>
left padding for the chart.
colors Object <optional>
custom colors
colors.fixToTitle boolean <optional>
true Whether bar-portions with the same title should also have the same color.
colors.background string <optional>
"#E3E6E9" the color of the background of the bars (not the color of background of the whole chart).
colors.text string <optional>
"black" the color of the text.
orientation 'vertical' | 'horizontal' <optional>
'vertical' orientation for the chart.
font string <optional>
'Roboto' the font for all writing. Font must be imported separately.
hover Object <optional>
options for the hover effect.
hover.visible boolean <optional>
true whether the titles should be shown on hover or not.
hover.callback function <optional>
function that returns html that is displayed in the hover effect. Receives (title, value).
distance 'variable' | number <optional>
'variable' whether the distance between timelines should be variable (based on svg size) or a fixed number of px.
minDistance number <optional>
0 the minimum number of pixels between bars.
adjustSize boolean <optional>
false whether the size of the container should be adjusted based on the needed space. Only works if params.distance != 'variable'.
scale Object <optional>
options for the scale
scale.visible boolean <optional>
true whether the scale should be visible or not
scale.interval number <optional>
10 the interval at which to draw the scale
scale.color number <optional>
"#E3E6E9" the color of the scale lines
draggable boolean <optional>
false whether the chart can be dragged
onScroll function <optional>
called when the user scrolls on the chart

View Source index.js, line 480

Will throw an error if the container element is not found.

Methods

setData(dataopt)

Replaces the existing data with new data.
Parameters:
Name Type Attributes Description
data array <optional>
the data to be displayed
labels Array.<string> <optional>
the labels underneath each bar
datasets Array.<Object> <optional>
each dataset represents one "block" of a bar. To create a stacked bar chart have multiple datasets.
datasets[].values Array.<number> the values for each "block" of a bar. Should be between 0 and 1.
datasets[].title string <optional>
the title for the dataset.

View Source index.js, line 926