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);
- Bar
- exports(_selection, _data) ⏏
- static
- .animationDuration(_x) ⇒
duration
|module
- .betweenBarsPadding(_x) ⇒
padding
|module
- .chartGradient(_x) ⇒
Array.<String>
|module
- .colorMap([_x]) ⇒
object
|module
- .colorSchema(_x) ⇒
colorSchema
|module
- .enableLabels([_x]) ⇒
Boolean
|module
- .exportChart(filename, title) ⇒
Promise
- .hasPercentage(_x) ⇒
boolean
|module
- .hasSingleBarHighlight(_x) ⇒
boolean
|module
- .height(_x) ⇒
height
|module
- .highlightBarFunction(_x) ⇒
highlightBarFunction
|module
- .isAnimated(_x) ⇒
isAnimated
|module
- .isHorizontal(_x) ⇒
isHorizontal
|module
- .labelsMargin([_x]) ⇒
number
|module
- .labelsNumberFormat([_x]) ⇒
string
|module
- .labelsSize([_x]) ⇒
number
|module
- .isLoading(flag) ⇒
boolean
|module
- .margin(_x) ⇒
margin
|module
.nameLabel(_x) ⇒number
|module
- .numberFormat(_x) ⇒
string
|module
- .on() ⇒
module
- .percentageAxisToMaxRatio(_x) ⇒
ratio
|module
- .shouldReverseColorList(_x) ⇒
boolean
|module
- .orderingFunction(_x) ⇒
function
|Module
.valueLabel(_x) ⇒valueLabel
|module
- .valueLocale([_x]) ⇒
LocaleObject
|module
- .width(_x) ⇒
width
|module
- .xAxisLabel(_x) ⇒
String
|module
- .xAxisLabelOffset(_x) ⇒
Number
|module
- .xTicks(_x) ⇒
Number
|module
- .yAxisLabel(_x) ⇒
String
|module
- .yAxisLabelOffset(_x) ⇒
Number
|module
- .yAxisPaddingBetweenChart(_x) ⇒
Number
|module
- .yTicks(_x) ⇒
Number
|module
- .animationDuration(_x) ⇒
- inner
- ~BarChartData :
Array.<Object>
- ~LocaleObject :
Object
- ~BarChartData :
- static
- exports(_selection, _data) ⏏
exports(_selection, _data) ⏏
This function creates the graph using the selection as container
Kind: Exported function
Param | Type | Description |
---|---|---|
_selection | D3Selection | A d3 selection that represents the container(s) where the chart(s) will be rendered |
_data | BarChartData | The 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
Param | Type | Default | Description |
---|---|---|---|
_x | Number | 1200 | Desired 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
Param | Type | Description |
---|---|---|
_x | Number | module | Padding 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
Param | Type | Description |
---|---|---|
_x | Array.<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
Param | Type | Default | Description |
---|---|---|---|
[_x] | object |
| Color 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
Param | Type | Description |
---|---|---|
_x | Array.<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
Param | Type | Default |
---|---|---|
[_x] | Boolean | false |
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
Param | Type | Description |
---|---|---|
filename | String | File title for the resulting picture |
title | String | Title 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
Param | Type | Description |
---|---|---|
_x | boolean | Should 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
Param | Type | Description |
---|---|---|
_x | boolean | Should 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
Param | Type | Description |
---|---|---|
_x | number | Desired 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
Param | Type | Description |
---|---|---|
_x | function | Desired 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
Param | Type | Description |
---|---|---|
_x | Boolean | Desired 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
Param | Type | Description |
---|---|---|
_x | number | Desired 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
Param | Type | Default | Description |
---|---|---|---|
[_x] | number | 7 | Margin 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
Param | Type | Default | Description |
---|---|---|---|
[_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
Param | Type | Default | Description |
---|---|---|---|
[_x] | number | 12 | label 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
Param | Type | Description |
---|---|---|
flag | boolean | Desired 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
Param | Type | Description |
---|---|---|
_x | object | Margin object to get/set |
exports.nameLabel(_x) ⇒ number
| module
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
Param | Type | Description |
---|---|---|
_x | number | Desired 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
Param | Type | Description |
---|---|---|
_x | string | = ',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
Param | Type | Description |
---|---|---|
_x | number | ratio 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
Param | Type | Description |
---|---|---|
_x | boolean | Should 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
Param | Type | Description |
---|---|---|
_x | function | A custom function that sets logic for ordering |
exports.valueLabel(_x) ⇒ valueLabel
| module
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
Param | Type | Description |
---|---|---|
_x | Number | Desired 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
Param | Type | Default | Description |
---|---|---|---|
[_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
Param | Type | Description |
---|---|---|
_x | number | Desired 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
Param | Type | Description |
---|---|---|
_x | String | Desired 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
Param | Type | Description |
---|---|---|
_x | Number | Desired 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
Param | Type | Description |
---|---|---|
_x | Number | = 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
Param | Type | Description |
---|---|---|
_x | String | Desired 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
Param | Type | Description |
---|---|---|
_x | Number | Desired 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
Param | Type | Description |
---|---|---|
_x | Number | = 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
Param | Type | Description |
---|---|---|
_x | Number | = 6 Desired number of vertical ticks for the graph |
exports~BarChartData : Array.<Object>
Kind: inner typedef of exports
Properties
Name | Type | Description |
---|---|---|
value | Number | Value of the group (required) |
name | String | Name of the group (required) |
Example
[
{
value: 1,
name: 'glittering'
},
{
value: 1,
name: 'luminous'
}
]
exports~LocaleObject : Object
Kind: inner typedef of exports
Properties
Name | Type | Description |
---|---|---|
decimal | String | the decimal point(e.g., ".") |
thousands | String | the group separator(e.g., ",") |
grouping | Array.<Number> | the array of group sizes(e.g., [3]), cycled as needed |
currency | Array.<String> | the currency prefix and suffix(e.g., ["$", ""]) |
numerals | Array.<String> | optional; an array of ten strings to replace the numerals 0 - 9. |
percent | String | optional; the percent sign(defaults to "%") |
minus | String | optional; the minus sign(defaults to hyphen - minus, "-") |
nan | String | optional; the not - a - number value(defaults "NaN") See some standard locale object values here. |
Example
{
"decimal": ",",
"thousands": ".",
"grouping": [3],
"currency": ["", "\u00a0€"]
}