Skip to main content

Bar

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

Example

const barChart = bar();

barChart
.height(500)
.width(800);

d3.select('.css-selector')
.datum(dataset)
.call(barChart);

exports(_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: static method of exports
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: static method of exports
Returns: String | null | module - Current a11yDescription or Chart module to chain calls
Access: public

ParamTypeDescription
_xString | nullDesired accessible description for the chart

animationDuration(_x) ⇒ duration | module​

Gets or Sets the duration of the animation

Kind: static method of exports
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: static method of exports
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: static method of exports
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: static method of exports
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: static method of exports
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​

If true, adds labels at the end of the bars

Kind: static method of exports
Returns: Boolean | module - Current value of enableLabels or Chart module to chain calls
Access: public

ParamTypeDefault
[_x]Booleanfalse

exportChart(filename, title) ⇒ Promise​

Chart exported to png and a download action is fired

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

ParamTypeDescription
filenameStringFile title for the resulting picture
titleStringTitle to add at the top of the exported picture

hasPercentage(_x) ⇒ boolean | module​

Gets or Sets the hasPercentage status

Kind: static method of exports
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: static method of exports
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: static method of exports
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: static method of exports
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. By default this is 'false'

Kind: static method of exports
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: static method of exports
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: static method of exports
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: static method of exports
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: static method of exports
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: static method of exports
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: static method of exports
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: static method of exports
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: static method of exports
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: static method of exports
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: static method of exports
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: static method of exports
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: static method of exports
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: static method of exports
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: static method of exports
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: static method of exports
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: static method of exports
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: static method of exports
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: static method of exports
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: static method of exports
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: static method of exports
Returns: Number | module - Current yTicks or Chart module to chain calls
Access: public

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

exports~BarChartData : Array.<Object>​

Kind: inner typedef of exports
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 exports
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€"]
}