0.4.0 • Published 9 months ago

@redsift/d3-rs-bars v0.4.0

Weekly downloads
72
License
MIT
Repository
github
Last release
9 months ago

d3-rs-bars

d3-rs-bars generate a range of bar charts. Supports stacked and un-stacked series, hovers and highlights.

Builds

Circle CI npm MIT

Example

View @redsift/d3-rs-bars on CodePen

Full example @redsift/d3-rs-bars as REFViewer on CodePen

View @redsift/d3-rs-bars Collection on CodePen

Bottom orientation

Sample bars with a bottom orientation

Left orientation as a series

Sample bars with a left orientation

Top orientation as time

Sample bars with a top orientation and time label

Right orientation as stacked time

Sample bar stack with a right orientation(https://bricks.redsift.cloud/reusable/d3-rs-bars.svg?_datum=[[1, 10],200,300,3000, 100,100, 1000]&orientation=right&fill=series)

Side-by-Side with highlight and legend

Sample bars with a bottom orientation(https://bricks.redsift.cloud/reusable/d3-rs-bars.svg?_datum=[[100, 1000],20000,30000,30000, 10000,10000, 10000]&orientation=bottom&stacked=false&legend=Alpha&legend=Omega&highlight=15000)

Usage

Browser

<script src="//static.redsift.io/reusable/d3-rs-bars/latest/d3-rs-bars.umd-es2015.min.js"></script>
<script>
	var chart = d3_rs_bars.html();
	chart.fill('global');
	d3.select('body').datum([ 1, 2, 3, 10, 100 ]).call(chart);
</script>

ES6

import { html as bars } from "@redsift/d3-rs-bars";
import { select } from "d3-selection";

let chart = bars();
select('body').datum([ 1, 2, 3, 10, 100 ]).call(chart);

Require

var chart = require("@redsift/d3-rs-bars");
var eml = chart.html();
...

Datum

Parameters

PropertyDescriptionTransitionPreview
classedString Customise SVG by adding, removing and toggling of CSS classes.N
backgroundSting, Array, Function Change the background colour of the SVG container. Background colour can be set using a colour name, rgb or hex value.YPreview of background property Examples: Bricks/CodePen
themeString Customise the chart theme including 'light'(default) and 'dark'.YPreview of theme property Examples: Bricks/ CodePen
fillSting, Array, Function Change the bar chart colour using a String which can take colour name, rgb or hex value as an argument. Using an Array of custom colours or use 'global' to generate random colour or supply a custom function.YPreview of fill property uisng an array of colours Preview of fill using random colours
styleString Custom CSS to inject into chart.N
width, heightInteger Resize the height and width of the chart. Default width: 420 pixels.YPreview of width and height property Examples: Bricks/CodePen
sizeInteger Resize the chart to a certain size changing both the width and height maintaining a default aspect ratio.YPreview of size property Examples: Bricks/CodePen
scaleInteger Scale the entire chart by the scaling value. Used to zoom the chart or compensate for high DPI displays when rasterized. Default scale: 1YPreview of the scale propertyExamples: Bricks/CodePen
marginNumber Change the chart margin inside of the SVG container. Default margin: 26.YPreview of margin property Examples: Bricks,CodePen
insetNumber Resize the space inside the chart margin for the main chart element. This excludes items like legends. Comparing Margin & Inset legend where the legend get distorded while using margin on using a big value.YPrview of inset propertyExamples: Bricks/CodePen
highlight(Array of)Integer Highlight an array of value or a particular value.YPreview of highlight propertyExamples: Bricks/CodePen
minValue,maxValueNumber Sets the minimum and maximum Value scale range. Note that for log scales, minValue must be > 0.YPreview of minValue and maxValue properties Examples: Bricks/CodePen
legend(Array of) String Add legends to the chart where array of String can be supply for multiple bar chart.NPreview of legendExamples: Bricks/CodePen
legendOrientationString Position the legend, positions include top, bottom, left or right. Default orientation : 'bottom'YPreview of legendOrientation propertyExamples: Bricks/CodePen
orientationString Set the orientation of the labels. Default oriented : left. Parameters include right,left,top and bottom.YPreview of orientation propertyExamples: Bricks/CodePen
rotateValue,rotateIndexInteger Rotate the Index or Value ticks in degree where positive degree represent clockwise rotation and negative degree anticlockwise rotation. Default rotation : 0.YPreview of rotateIndex & rotateValue Examples: Bricks/CodePen
labelTimeString Interpret the label as a millisecond epoch and format it using specified string.NlabelTime=%a %bExamples: Bricks/CodePen
barSizeInterger Change the size of the bar elements. Positive value set the absolute value in pixels. Negative values specify the scale relative to space between ticks. i.e. -0.5 will set the bar size to 50% of the width between the ticks. Default size set to 6.YFixed bar sizeAbove Brick ExampleDynamic bar sizeAbove Brick Example / CodePen
tickDisplayValueString, Integer Rename all tick to a single argument by supplying a String or a Number.NPreview of tickDisplayValue propertyExamples: Bricks/CodePen
labelString Use the same labels for value using a String or an Integer.NPreview of label propertyExamples: Bricks/CodePen
tickFormatValue, tickFormatIndexString, Function Set the formatting string or function for the ticks.N[Preview of tickFormatValue & tickFormatIndexExamples: Bricks/ CodePen
tickCountValue, tickCountIndexNumber, String, Interval Function Hints at the number of ticks to set in the corresponding axis. Supports strings for example split time intervals, apply when using epoch time format. Default tickCountIndex: 6NPreview of tickCountIndex & tickCountValue propertes Examples: Bricks/CodePens
displayTipInteger Position the tip display on the bar chart on hovering.YCodePen Example
displayHtmlString,Function Customise the tip info. Function parameters include (d,i), d represent data and i the dataset.NCodePen Example
stackedBoolean Enable bar chart to stack onto each other.YPreview of StackedExamples: Bricks/CodePen
valueFunction Generate a bar chart from selecting an object values carrying the data to generate the bar chart.NCodePen Example
gridBoolean Enable grid to display on the chart. Default: true.NPreview of grid propertyExamples: Bricks/CodePen
logValueInteger Alter the grid spacing for value.YPreview of logValueExamples: Bricks/CodePen
languageString Change the language format of the chart affecting digit, currency and time formats.NCodePen Example

Time

The two main time formatter available are UTC and Local Time. UTC uses the time standard applied across the world which is unaffected by Daylight Saving Time whereas Local Time is set to your local timezone. To use any of the formatters, string specifiers is passed to the labelTime function. To apply UTC format, d3.utcFormat(specifier) is used as a parameter to labelTime, specifier being the string specifiers. When using Local Time, only string specifiers can be passed to labelTime since by default the time format is set to Local Time.

Additional information about Time format for D3 can be found here.