Giter Club home page Giter Club logo

lollipop-chart's Introduction

lollipopChart

The lollipop chart provides a visualization of values compared to their own comparison value. The value is the lollipop and the comparison is the bar.

Look at the Demo

Getting Started

LollipopChart is a UMD module, you can add the javascript in a scripts tag or require it using something like webpack. D3 must either be available in the global namespace or bundled in with your bundle tool. For the global namespace method download lollipopChart.js, put something like the following in your and you should be good to go.

<script src="d3.js" charset="utf-8"></script>
<script src="lollipopChart.js" charset="utf-8"></script>

Example

HTML would look something like this

<!DOCTYPE html>
<html lang="en-US">
	<head>
		<script src="d3.js" charset="utf-8"></script>
		<script src="lollipopChart.js" charset="utf-8"></script>
		
	</head>
	<body>
		<div id="myLollipopChart"></div>	
	</body>
	<script src="index.js"></script>
</html>

And the index.js here would contain something like this

var lollipopChart = LollipopChart('#myLollipopChart'); //you can also use the commonJs way if you're bundling everything with something like webpack
var gradesPerName = [
    {name: 'Bobby', value: 80, comparisonValue: 80},
    {name: 'Jane', value: 79, comparisonValue: 68},
    {name: 'Fred', value: 70, comparisonValue: 78},
    {name: 'Alan', value: 75, comparisonValue: 64},
    {name: 'Jeeves', value: 75, comparisonValue: 85},
    {name: 'Mary', value: 67, comparisonValue: 70},
    {name: 'Marsha', value: 60, comparisonValue: 68},
    {name: 'Andy', value: 100, comparisonValue: 100},
  ];
lollipopChartBasic
	.render(gradesPerName);

API Reference

LollipopChart

Kind: global class

new LollipopChart(selection)

Lollipop chart implementation.

Param Type Description
selection String any valid d3 selector. This selector is used to place the chart.

lollipopChart.render([data]) ⇒ LollipopChart

Render the LollipopChart instance. Simply renders chart when called with parameter. Updates data, then renders, if called with parameter

Kind: instance method of LollipopChart

Param Type
[data] Object

lollipopChart.data([data]) ⇒ Object | LollipopChart

Get/set the data for the LollipopChart instance. Data should be in the form of an array of objects with name, value, and comparisonValue. Ex. [{name: 'USA', value: 17, comparisonValue: 20}, {name: 'Canada', value: 14, comparisonValue: 10}] Data can also specify a scale to use for only that data object like {name: 'Alberia', value: 23, comparisonValue: 44, scale: d3.scale.linear().domain([0, 50])} For individual scales, a domain must be set for that scale.

Kind: instance method of LollipopChart
Returns: Object - [Acts as getter if called with no parameter]LollipopChart - [Acts as setter if called with parameter]

Param Type
[data] Object

lollipopChart.tooltipContent([tooltipContentFunction(datum)]) ⇒ Object | LollipopChart

Get/set the color tooltip content function for the LollipopChart instance. The default will return a function with content for displaying the Name, Value, and Comparison Value in a tooltip

Kind: instance method of LollipopChart
Returns: Object - [Acts as getter if called with no parameter]LollipopChart - [Acts as setter if called with parameter]

Param Type
[tooltipContentFunction(datum)] function

lollipopChart.colorScale([scale]) ⇒ Object | LollipopChart

Get/set the color scale for the LollipopChart instance. The color scale is set by default to d3.scale.category10

Kind: instance method of LollipopChart
Returns: Object - [Acts as getter if called with no parameter]LollipopChart - [Acts as setter if called with parameter]

Param Type
[scale] Object

lollipopChart.noDataColor([color]) ⇒ string | LollipopChart

Get/set the no-data-color for the LollipopChart instance.

Kind: instance method of LollipopChart
Returns: string - [Acts as getter if called with no parameter]LollipopChart - [Acts as setter if called with parameter]

Param Type
[color] string

lollipopChart.yScale([d3 scale]) ⇒ Object | LollipopChart

Get/set the y-scale for the LollipopChart instance. If this is not set, the chart will calculate the scale domain as the min and max of the data values passed into the chart. Set this scale if you need a global scale. Note that individual scales are allowed if any data object has a scale property on it like {name: 'Bob', value: 25, comparisonValue: 45, scale: d3.scale.linear()}

Kind: instance method of LollipopChart
Returns: Object - [Acts as getter if called with no parameter]LollipopChart - [Acts as setter if called with parameter]

Param Type
[d3 scale] Object

lollipopChart.barGap([barGap]) ⇒ number | LollipopChart

Get/set the gap between bars for the LollipopChart instance.

Kind: instance method of LollipopChart
Returns: number - [Acts as getter if called with no parameter]LollipopChart - [Acts as setter if called with parameter]

Param Type
[barGap] number

lollipopChart.lollipopRadius([radius]) ⇒ number | LollipopChart

Get/set the lollipop radius for the LollipopChart instance.

Kind: instance method of LollipopChart
Returns: number - [Acts as getter if called with no parameter]LollipopChart - [Acts as setter if called with parameter]

Param Type
[radius] number

lollipopChart.width([width]) ⇒ number | LollipopChart

Get/set the chart width for the LollipopChart instance.

Kind: instance method of LollipopChart
Returns: number - [Acts as getter if called with no parameter]LollipopChart - [Acts as setter if called with parameter]

Param Type
[width] number

lollipopChart.height([height]) ⇒ number | LollipopChart

Get/set the chart height for the LollipopChart instance.

Kind: instance method of LollipopChart
Returns: number - [Acts as getter if called with no parameter]LollipopChart - [Acts as setter if called with parameter]

Param Type
[height] number

lollipopChart.valueAccessor([valueAccessorFunc]) ⇒ function | LollipopChart

Get/set the value accessor for the LollipopChart instance.

Kind: instance method of LollipopChart
Returns: function - [Acts as getter if called with no parameter]LollipopChart - [Acts as setter if called with parameter]

Param Type
[valueAccessorFunc] function

lollipopChart.nameAccessor([nameAccessorFunc]) ⇒ function | LollipopChart

Get/set the name accessor for the LollipopChart instance.

Kind: instance method of LollipopChart
Returns: function - [Acts as getter if called with no parameter]LollipopChart - [Acts as setter if called with parameter]

Param Type
[nameAccessorFunc] function

lollipopChart.comparisonValueAccessor([comparisonValueAccessorFunc]) ⇒ function | LollipopChart

Get/set the comparison value accessor for the LollipopChart instance.

Kind: instance method of LollipopChart
Returns: function - [Acts as getter if called with no parameter]LollipopChart - [Acts as setter if called with parameter]

Param Type
[comparisonValueAccessorFunc] function

lollipopChart.transitionDuration([transitionDuration]) ⇒ number | LollipopChart

Get/set the transition duration for the LollipopChart instance.

Kind: instance method of LollipopChart
Returns: number - [transitionDuration]LollipopChart - [Acts as setter if called with parameter]

Param Type
[transitionDuration] number

lollipop-chart's People

Contributors

ajessee avatar billymonks avatar jackcompton avatar tehandyb avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lollipop-chart's Issues

Negative heights for rectangles

This can happen if the relative scale is used, and a datum comparisonValue is less than its value. This is like plugging in a value smaller than the lower end of a domain, and the result will come out to be a negative range value.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.