Skip to main content

sparkline

Sparkline

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

Requires: module:d3-array,
Example

const sparkLineChart = sparkline();

sparkLineChart
.width(200)
.height(100);

d3Selection.select('.css-selector')
.datum(dataset)
.call(sparkLineChart);

exports(_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

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.areaGradient(_x) ⇒ areaGradient | module

Gets or Sets the areaGradient of the chart

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

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

exports.dateLabel(_x) ⇒ dateLabel | module

Deprecated

Gets or Sets the dateLabel of the chart

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

ParamTypeDescription
_xnumberDesired dateLabel for the graph

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

ParamTypeDefaultDescription
_xnumber30Desired height for the graph

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

ParamTypeDefaultDescription
_xbooleanfalseDesired animation flag

exports.lineGradient(_x) ⇒ lineGradient | module

Gets or Sets the lineGradient of the chart

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

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

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) ⇒ object | module

Gets or Sets the margin of the chart

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

ParamTypeDescription
_xobjectMargin object to get/set

exports.titleText(_x) ⇒ string | module

Gets or Sets the text of the title at the top of sparkline. To style the title, use the titleTextStyle method below.

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

ParamTypeDescription
_xstring= null String to set

exports.titleTextStyle(_x) ⇒ Object | module

Gets or Sets the text style object of the title at the top of sparkline. Using this method, you can set font-family, font-size, font-weight, font-style, and color (fill). The default text font settings:

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

ParamTypeDescription
_xobjectObject with text font configurations

Example

<pre>
<code>
{
'font-family': 'sans-serif',
'font-size': '22px',
'font-weight': 0,
'font-style': 'normal',
'fill': linearGradient[0]
}
</code>
</pre>

You can set attributes individually. Setting just 'font-family'
within the object will set custom 'font-family` while the rest
of the attributes will have the default values provided above.

Example

sparkline.titleTextStyle({
'font-family': 'Roboto',
'font-size': '1.5em',
'font-weight': 600,
'font-style': 'italic',
'fill': 'lightblue'
})

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

ParamTypeDefaultDescription
_xnumber100Desired width for the graph

exports~SparklineChartData : Array.<Object>

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