Skip to main content

Sparkline

Sparkline Chart reusable API module that allows us rendering a sparkline configurable chart.

Example

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

// dataset: [{ date, value }]
const sparklineChart = sparkline();

sparklineChart
.width(200)
.height(100)
.render('.css-selector', dataset);

sparkline(_selection, _data)​

This function creates the graph using the selection and data provided

Kind: Exported function

ParamTypeDescription
_selectionD3SelectionA d3 selection that represents the container(s) where the chart(s) will be rendered
_dataSparklineChartDataThe 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 "Sparkline".

Kind: method of sparkline
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 sparkline
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 sparkline
Returns: Boolean | module - Current a11yDataTable or Chart module to chain calls
Access: public

ParamTypeDescription
_xBooleanWhether to render the data table

animationDuration(_x) ⇒ duration | module​

Gets or Sets the duration of the animation

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

ParamTypeDefaultDescription
_xnumber1200Desired animation duration for the graph

areaGradient(_x) ⇒ areaGradient | module​

Gets or Sets the areaGradient of the chart

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

ParamTypeDescription
_xArray.<string>= ['#F5FDFF', '#F6FEFC'] Desired areaGradient for the graph

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 sparkline
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

height(_x) ⇒ height | module​

Gets or Sets the height of the chart

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

ParamTypeDefaultDescription
_xnumber30Desired height for the graph

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 sparkline
Returns: isAnimated | module - Current isAnimated flag or Chart module
Access: public

ParamTypeDefaultDescription
_xbooleanfalseDesired animation flag

lineGradient(_x) ⇒ lineGradient | module​

Gets or Sets the lineGradient of the chart

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

ParamTypeDescription
_xArray.<string>= colorHelper.colorGradients.greenBlue Desired lineGradient for the graph

isLoading(flag) ⇒ boolean | module​

Gets or Sets the loading state of the chart

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

ParamTypeDescription
flagbooleanDesired value for the loading state

margin(_x) ⇒ object | module​

Gets or Sets the margin of the chart

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

ParamTypeDescription
_xobjectMargin object to get/set

width(_x) ⇒ width | module​

Gets or Sets the width of the chart

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

ParamTypeDefaultDescription
_xnumber100Desired width for the graph

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 sparkline
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

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

exports~SparklineChartData : Array.<Object>​

Kind: inner typedef of sparkline
Properties

NameTypeDescription
valuenumberValue of the group (required)
namestringName of the group (required)

Example

[
{
value: 1,
date: '2011-01-06T00:00:00Z'
},
{
value: 2,
date: '2011-01-07T00:00:00Z'
}
]