Skip to main content

Bar

Bar Chart reusable API class that renders a simple and configurable bar chart.

Example

import { bar } from '@britecharts/core';

// dataset: [{ name, value }]
const barChart = bar();

barChart
.height(500)
.width(800)
.render('.css-selector', dataset);

bar(_selection, _data)​

This function creates the graph using the selection as container

Kind: Exported function

ParamTypeDescription
_selectionD3SelectionA d3 selection that represents the container(s) where the chart(s) will be rendered
_dataBarChartDataThe data to attach and generate the chart

a11yTitle(_x) ⇒ String | null | module​

Gets or Sets the name screen readers announce for the chart. It is set as the svg's aria-label. Unset, the chart is announced as "Bar chart".

Kind: method of bar
Returns: String | null | module - Current a11yTitle or Chart module to chain calls
Access: public

ParamTypeDescription
_xString | nullDesired accessible title for the chart

a11yDescription(_x) ⇒ String | null | module​

Gets or Sets a longer description screen readers announce after the chart's name, such as what the data shows. It is rendered as the svg's <desc>. Unset, the chart has no description.

Kind: method of bar
Returns: String | null | module - Current a11yDescription or Chart module to chain calls
Access: public

ParamTypeDescription
_xString | nullDesired accessible description for the chart

a11yDataTable(_x) ⇒ Boolean | module​

Gets or Sets whether the chart renders its data as a visually hidden table after its svg, which screen readers can read cell by cell. On by default; set it to false when the app gives the data its own accessible form.

Kind: method of bar
Returns: Boolean | module - Current a11yDataTable or Chart module to chain calls
Access: public

ParamTypeDescription
_xBooleanWhether to render the data table

a11yKeyboardNavigation(_x) ⇒ Boolean | module​

Gets or Sets whether a keyboard can move through the chart's data points: the chart takes one tab stop, the arrow keys move between points, Home and End go to the first and last, and Escape lets go. The tooltip and highlights follow focus as they follow the pointer. On by default.

Kind: method of bar
Returns: Boolean | module - Current a11yKeyboardNavigation or Chart module to chain calls
Access: public

ParamTypeDescription
_xBooleanWhether the keyboard can move through the data

animationDuration(_x) ⇒ duration | module​

Gets or Sets the duration of the animation

Kind: method of bar
Returns: duration | module - Current animation duration or Chart module to chain calls
Access: public

ParamTypeDefaultDescription
_xNumber1200Desired animation duration for the graph

betweenBarsPadding(_x) ⇒ padding | module​

Gets or Sets the padding of the chart (Default is 0.1)

Kind: method of bar
Returns: padding | module - Current padding or Chart module to chain calls
Access: public

ParamTypeDescription
_xNumber | modulePadding value to get/set

chartGradient(_x) ⇒ Array.<String> | module​

Gets or Sets the gradient colors of a bar in the chart

Kind: method of bar
Returns: Array.<String> | module - Current color gradient or Line Chart module to chain calls
Access: public

ParamTypeDescription
_xArray.<String>Desired color gradient for the line (array of two hexadecimal numbers)

colorMap([_x]) ⇒ object | module​

Gets or Sets the colorMap of the chart

Kind: method of bar
Returns: object | module - Current colorMap or Chart module to chain calls
Access: public

ParamTypeDefaultDescription
[_x]object
Color map

Example

barChart.colorMap({name: 'colorHex', name2: 'colorString'})

colorSchema(_x) ⇒ colorSchema | module​

Gets or Sets the colorSchema of the chart

Kind: method of bar
Returns: colorSchema | module - Current colorSchema or Chart module to chain calls
Access: public

ParamTypeDescription
_xArray.<String>Desired colorSchema for the graph

enableLabels([_x]) ⇒ Boolean | module​

Use hasLabels, which does the same. Goes in version 4.

If true, adds labels at the end of the bars

Kind: method of bar
Returns: Boolean | module - Current value of hasLabels or Chart module to chain calls
Access: public

ParamTypeDefault
[_x]Booleanfalse

exportChart(filename, title) ⇒ Promise​

Exports the chart and fires a download: an svg file when the filename ends in .svg, and a png otherwise

Kind: method of bar
Returns: Promise - Promise that resolves if the chart image was loaded and downloaded successfully
Access: public

ParamTypeDescription
filenameStringName of the downloaded file, whose extension picks the format
titleStringTitle to add at the top of the exported picture

hasLabels([_x]) ⇒ Boolean | module​

If true, adds labels at the end of the bars

Kind: method of bar
Returns: Boolean | module - Current value of hasLabels or Chart module to chain calls
Access: public

ParamTypeDefault
[_x]Booleanfalse

hasPercentage(_x) ⇒ boolean | module​

Gets or Sets the hasPercentage status

Kind: method of bar
Returns: boolean | module - Is percentage used or Chart module to chain calls
Access: public

ParamTypeDescription
_xbooleanShould use percentage as value format

hasSingleBarHighlight(_x) ⇒ boolean | module​

Gets or Sets the hasSingleBarHighlight status. If the value is true (default), only the hovered bar is considered to be highlighted and will be darkened by default. If the value is false, all the bars but the hovered bar are considered to be highlighted and will be darkened (by default). To customize the bar highlight or remove it completely, use highlightBarFunction instead.

Kind: method of bar
Returns: boolean | module - Is hasSingleBarHighlight used or Chart module to chain calls
Access: public

ParamTypeDescription
_xbooleanShould highlight the hovered bar

height(_x) ⇒ height | module​

Gets or Sets the height of the chart

Kind: method of bar
Returns: height | module - Current height or Chart module to chain calls
Access: public

ParamTypeDescription
_xnumberDesired width for the graph

highlightBarFunction(_x) ⇒ highlightBarFunction | module​

Gets or Sets the highlightBarFunction function. The callback passed to this function returns a bar selection from the bar chart. Use this function if you want to apply a custom behavior to the highlighted bar on hover. When hasSingleBarHighlight is true the highlighted bar will be the one that was hovered by the user. When hasSingleBarHighlight is false the highlighted bars are all the bars but the hovered one. The default highlight effect on a bar is darkening the highlighted bar(s) color.

Kind: method of bar
Returns: highlightBarFunction | module - Is highlightBarFunction used or Chart module to chain calls
Access: public

ParamTypeDescription
_xfunctionDesired operation operation on a hovered bar passed through callback

Example

barChart.highlightBarFunction(bar => bar.attr('fill', 'blue'))
barChart.highlightBarFunction(null) // will disable the default highlight effect

isAnimated(_x) ⇒ isAnimated | module​

Gets or Sets the isAnimated property of the chart, making it to animate when render. The chart draws without animation when the reader's system asks for reduced motion (prefers-reduced-motion), whatever this is set to. By default this is 'false'

Kind: method of bar
Returns: isAnimated | module - Current isAnimated flag or Chart module
Access: public

ParamTypeDescription
_xBooleanDesired animation flag

isHorizontal(_x) ⇒ isHorizontal | module​

Gets or Sets the horizontal direction of the chart

Kind: method of bar
Returns: isHorizontal | module - If it is horizontal or Chart module to chain calls
Access: public

ParamTypeDescription
_xnumberDesired horizontal direction for the graph

labelsMargin([_x]) ⇒ number | module​

Offset between end of bar and start of the percentage bars

Kind: method of bar
Returns: number | module - Current offset or Chart module to chain calls
Access: public

ParamTypeDefaultDescription
[_x]number7Margin offset from end of bar

labelsNumberFormat([_x]) ⇒ string | module​

Gets or Sets the labels number format

Kind: method of bar
Returns: string | module - Current labelsNumberFormat or Chart module to chain calls
Access: public

ParamTypeDefaultDescription
[_x]string"&quot;,f&quot;"desired label number format for the bar chart

labelsSize([_x]) ⇒ number | module​

Get or Sets the labels text size

Kind: method of bar
Returns: number | module - Current text size or Chart module to chain calls
Access: public

ParamTypeDefaultDescription
[_x]number12label font size

isLoading(flag) ⇒ boolean | module​

Gets or Sets the loading state of the chart

Kind: method of bar
Returns: boolean | module - Current loading state flag or Chart module to chain calls
Access: public

ParamTypeDescription
flagbooleanDesired value for the loading state

margin(_x) ⇒ margin | module​

Gets or Sets the margin of the chart

Kind: method of bar
Returns: margin | module - Current margin or Chart module to chain calls
Access: public

ParamTypeDescription
_xobjectMargin object to get/set

numberFormat(_x) ⇒ string | module​

Gets or Sets the number format of the bar chart

Kind: method of bar
Returns: string | module - Current numberFormat or Chart module to chain calls
Access: public

ParamTypeDescription
_xstring= ',f' Desired numberFormat for the chart. See examples here

on() ⇒ module​

Exposes an 'on' method that acts as a bridge with the event dispatcher We are going to expose this events: customMouseOver, customMouseMove, customMouseOut, and customClick

Kind: method of bar
Returns: module - Bar Chart
Access: public

percentageAxisToMaxRatio(_x) ⇒ ratio | module​

Configurable extension of the x axis. If your max point was 50% you might want to show x axis to 60%, pass 1.2

Kind: method of bar
Returns: ratio | module - Current ratio or Chart module to chain calls
Access: public

ParamTypeDescription
_xnumberratio to max data point to add to the x axis

shouldReverseColorList(_x) ⇒ boolean | module​

Gets or Sets whether the color list should be reversed or not

Kind: method of bar
Returns: boolean | module - Is color list being reversed or Chart module to chain calls
Access: public

ParamTypeDescription
_xbooleanShould reverse the color list

orderingFunction(_x) ⇒ function | Module​

Changes the order of items given the custom function

Kind: method of bar
Returns: function | Module - A custom ordering function or Chart module to chain calls
Access: public

ParamTypeDescription
_xfunctionA custom function that sets logic for ordering

valueLocale([_x]) ⇒ LocaleObject | module​

Gets or Sets the locale which our formatting functions use. Check the d3-format docs for the required values.

Kind: method of bar
Returns: LocaleObject | module - Current locale object or Chart module to chain calls
Access: public

ParamTypeDefaultDescription
[_x]LocaleObject
_x Desired locale object format.

Example

barChart
.valueLocale({thousands: '.', grouping: [3], currency: ["$", ""], decimal: "."})

width(_x) ⇒ width | module​

Gets or Sets the width of the chart

Kind: method of bar
Returns: width | module - Current width or Chart module to chain calls
Access: public

ParamTypeDescription
_xnumberDesired width for the graph

xAxisLabel(_x) ⇒ String | module​

Gets or Sets the text of the xAxisLabel on the chart

Kind: method of bar
Returns: String | module - Label or Chart module to chain calls
Access: public

ParamTypeDescription
_xStringDesired text for the label

xAxisLabelOffset(_x) ⇒ Number | module​

Gets or Sets the offset of the xAxisLabel on the chart

Kind: method of bar
Returns: Number | module - label or Chart module to chain calls
Access: public

ParamTypeDescription
_xNumberDesired offset for the label

xTicks(_x) ⇒ Number | module​

Gets or Sets the number of ticks of the x axis on the chart

Kind: method of bar
Returns: Number | module - Current xTicks or Chart module to chain calls
Access: public

ParamTypeDescription
_xNumber= 5 Desired horizontal ticks

yAxisLabel(_x) ⇒ String | module​

Gets or Sets the text of the yAxisLabel on the chart

Kind: method of bar
Returns: String | module - Label or Chart module to chain calls
Access: public

ParamTypeDescription
_xStringDesired text for the label

yAxisLabelOffset(_x) ⇒ Number | module​

Gets or Sets the offset of the yAxisLabel on the chart

Kind: method of bar
Returns: Number | module - Label or Chart module to chain calls
Access: public

ParamTypeDescription
_xNumberDesired offset for the label

yAxisPaddingBetweenChart(_x) ⇒ Number | module​

Space between y axis and chart

Kind: method of bar
Returns: Number | module - Current value of yAxisPaddingBetweenChart or Chart module to chain calls
Access: public

ParamTypeDescription
_xNumber= 10 Space between y axis and chart

yTicks(_x) ⇒ Number | module​

Gets or Sets the number of vertical ticks on the chart

Kind: method of bar
Returns: Number | module - Current yTicks or Chart module to chain calls
Access: public

ParamTypeDescription
_xNumber= 6 Desired number of vertical ticks for the graph

tooltip(_x) ⇒ module | null​

Gets or Sets the tooltip the chart shows: a tooltip(), set on this chart only. The chart connects it to its pointer and keyboard events, draws it in place, and sets the labels its data points need, unless they were set on the tooltip; it does so now if the chart has drawn, and again on every draw. Its event handlers go under the britechartsTooltip namespace. Null, or another tooltip, removes the one it had.

Kind: method of bar
Returns: module | null - Current tooltip or Chart module to chain calls
Throws:

  • Error When the tooltip is already set on another chart

Access: public

ParamTypeDescription
_xmodule | nullThe tooltip to show

Example

bar().tooltip(tooltip().title('Uses')).render('#chart', data);

render(target, [data]) ⇒ module​

Draws the chart into a target: a CSS selector, an element or a d3 selection, as select(target).datum(data).call(chart) does. A selector draws into the first element it matches. Without data, the chart redraws with the data it last drew there.

Kind: method of bar
Returns: module - The chart module, to chain calls
Throws:

  • Error When the target matches no element

Access: public

ParamTypeDescription
targetString | Element | D3SelectionWhere to draw the chart
[data]ObjectThe data to draw

Example

bar().width(600).render('#chart', data);

exports~BarChartData : Array.<Object>​

Kind: inner typedef of bar
Properties

NameTypeDescription
valueNumberValue of the group (required)
nameStringName of the group (required)

Example

[
{
value: 1,
name: 'glittering'
},
{
value: 1,
name: 'luminous'
}
]

exports~LocaleObject : Object​

Kind: inner typedef of bar
Properties

NameTypeDescription
decimalStringthe decimal point(e.g., ".")
thousandsStringthe group separator(e.g., ",")
groupingArray.<Number>the array of group sizes(e.g., [3]), cycled as needed
currencyArray.<String>the currency prefix and suffix(e.g., ["$", ""])
numeralsArray.<String>optional; an array of ten strings to replace the numerals 0 - 9.
percentStringoptional; the percent sign(defaults to "%")
minusStringoptional; the minus sign(defaults to hyphen - minus, "-")
nanStringoptional; the not - a - number value(defaults "NaN") See some standard locale object values here.

Example

{
"decimal": ",",
"thousands": ".",
"grouping": [3],
"currency": ["", "\u00a0€"]
}