Funnel Graph JS is a library for generating a funnel chart. It generates an SVG chart, adds labels, legend and other info. Some of the features include generating horizontal and vertical funnel charts, applying solid colors and gradients, possibility to generate a two-dimensional funnel chart.
FunnelGraph.js is also available as a Vue.js component: Vue Funnel Graph
Table of Contents
You can get the code by installing the NPM package, loading files from a CDN or downloading the repo.
Run the following script to install:
npm i funnel-graph-js
Download the repo ZIP, add
theme.min.css to include the styling for labels, legend etc.
It is recommended to add the theme, to display the chart correctly.
FunnelGraph.js is built in a way that most of the styling is controlled by theme file,
so it is possible to adapt every element to your design. The chart is a SVG element and
colors property of the options controls the colors of the chart.
var graph =container: '.funnel'gradientDirection: 'horizontal'data: ...displayPercent: truedirection: 'horizontal';graph;
You can choose how you want to display your data on funnel graph. You can display exact numbers, you can display percentages or both. The library will generate percentages automatically, taking the largest number as 100% and then calculating other numbers as a fraction of the largest number. For example: 12000, 5700 and 360 will be displayed as 47.5% and 3% (100% is skipped in order to avoid redundancy).
If you want to hide percentages you set
You can also display a vertical funnel graph:
If you want to add a solid color to your funnel:
And if you want a gradient:
color: 'orange' 'red';
An array containing only one color will have the same effect as passing a single color as a string.
If you are using a gradient you can control the gradient direction using:
gradientDirection: 'vertical'; // defaults to 'horizontal'
There are 3 ways to define data for the funnel graph.
The most simple way is do define a data array:
data: 12000 5700 360;
this will create the data without any titles. However you can still display the values as percentages, as number or both.
If you want to add labels to your numbers pass an array of labels to
data:labels: 'Impressions' 'Add To Cart' 'Buy'colors: 'orange' 'red'values: 12000 5700 360
That most explicit way to add data to the funnel graph.
If using one of those two ways, you can control the graph
colors param. Otherwise, the default color will be used.
And if you are using gradient as color, then you can control
gradient direction with
colors shall be passed inside
gradientDirection with other options.
Otherwise it defaults to horizontal (left to right).
Two-dimensional funnel graph
If you want to break down your data into more details, you can use two-dimensional svg funnel graph. It will generate a graph like this:
In this example we will add more details to the previous example. We have Impressions, Add To Cart and Buy data, however this time we also want to visualize the data sources. So we want to see the traffic sources, how much of them are direct, from ads and from social media.
data:labels: 'Impressions' 'Add To Cart' 'Buy'subLabels: 'Direct' 'Social Media' 'Ads'colors:'#FFB178' '#FF78B1' '#FF3C8E''red''blue'values:2000 4000 60003000 1000 1700200 30 130
In a two-dimensional graph each segment shall have it's own color or gradient.
If using a gradient the
gradientDirection option will be applied to all of the segments.
However all supported ways of defining colors in a simple funnel graph can be used here as
well and you can have both solid colors and gradients applied to segments of a single graph.
In the above example first segment, "Direct", will have a gradient,
"Social Media" will have a solid red color, and "Ads" segment will have a solid blue.
||Selector of the element that will hold the chart||
||Whether the chart visualization is displayed vertically or horizontally||
||Whether the gradient applied to the segments of the graph is displayed from top to bottom or from left to right||
||Whether to display the automatically calculated percentage values below the labels||
||Object containing information about values, labels and colors of the chart||
||Width of the funnel graph||
||Height of the funnel graph||
||Whether display percentage or real value of segment||
||Whether to hide sub labels based sub label visibility array||
||Array that maps to the number of values in data.subLablels. True will display, false will hide.||
||Display chart vertically|
||Display chart horizontally|
||Toggle direction of chart|
||Display gradient on all sections from top to bottom|
||Display gradient on all sections from left to right|
||Toggle direction of gradient on all sections|
||Update funnel graph height|
||Update funnel graph width|
||Update funnel graph data||
||Update funnel options||