Skip to main content

bar

Bar

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

Requires: module:d3-array,
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

exports.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

exports.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

exports.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)

exports.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]objectColor map

Example

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

exports.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

exports.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

exports.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

exports.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

exports.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

exports.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

exports.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

exports.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

exports.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

exports.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

exports.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"\",f\""desired label number format for the bar chart

exports.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

exports.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

exports.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

exports.nameLabel(_x) ⇒ number | module

Deprecated

Gets or Sets the nameLabel of the chart

Kind: static method of exports
Returns: number | module - Current nameLabel or Chart module to chain calls
Access: public

ParamTypeDescription
_xnumberDesired nameLabel for the graph

exports.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

exports.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

exports.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

exports.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

exports.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

exports.valueLabel(_x) ⇒ valueLabel | module

Deprecated

Gets or Sets the valueLabel of the chart

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

ParamTypeDescription
_xNumberDesired valueLabel for the graph

exports.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: "."})

exports.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

exports.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

exports.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

exports.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

exports.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

exports.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

exports.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

exports.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€"]
}