Grafico javascript charting library Documentation

Grafico is a graphing library based on Raphaël and Prototype.js. It is originally developed as Ico by Alex Young, but this version was developed by Kilian Valkhof at Wakoopa. Grafico's basic principles are to provide good, clean looking graphs inspired by work of Stephen Few and Edward Tufte, while still being flexible to implement and providing numerous api options to tweak the look of the graphs.

Some key things Grafico supports:

Basics

Grafico graphs are initiated via this function call:

var foo = new Grafico.GraphType($(element), data, options);

$(element) is a prototype id selector, data is an object or array (depending on the graph) and options is optional and an object.

Dependencies

Supported graph types:

Tested on

Notable additions

Base graph options:

background_color
The background color of the graph (string, example: "#fff")
Default value: backgroundcolor of $(element), else #fff
colors
Select the colors for the lines or bars (object)
Default value: random colors
datalabels
For line graphs: Add a hover with the text, and append the text to the marker hover, per line (object, example: {workload:'My workload'})
Can also be a function, to render custom labels, e.g. {workload:function(idx, value) { return ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'][idx] + " : " + value} }} for bar graphs: append a text per bar. (object, example: {workload: ["1","2","5"]})
Default value: empty
draw_axis
Show or hide the axis lines (boolean)
Default value: true
draw_hovers
Show or hide hovers on line, area and stack charts (different from markers) (boolean)
Default value: false
draw_focus
Draw the focus lines on graphs with a non-zero starting point (boolean)
Default value: true
font_size
The font-size for the axis and hovers (number)
Default value: 10
grid
Draw a grid or not (boolean)
Default value: true
grid_color
The color of the gridlines (string, example: "#fff")
Default value: "#ccc"
height
Specify the height of the element (number)
Default value: height of $(element)
hover_color
Color a bar or line should fade to on hover (string, example: "#fff")
Default value: empty
hover_text_color
The color of the text in the hovers (string, example: "#fff")
Default value: "#fff"
labels
The labels being displayed on the horizontal axis (array of strings)
Default value: numerical
label_color
The color of the axis, axis values and hovers (string, example: "#fff")
Default value: "#000"
label_max_size
If set, labels will be truncated to that number and an … will be added. (number, int)
Default value: false
label_rotation
Rotate the horizontal labels, in degrees. known limitation: it rotates around the center of the label (number)
Default value: 0
left_padding
Set a standard left spacing regardless of vertical axis label width (number)
Default value: false
meanline
Display a line on the average of all datapoints. Accepts all Raphael parameters (object or boolean, example: { 'stroke-width': '2px', stroke: '#000' })
Default value: false, setting it to true will draw a 2px grey line.
normaliser
Allows you to use your own normaliser instead of the built-in one (prototype class)
Default value: built-in normaliser
padding_top
The amount of padding above the graph (number)
Default value: 20
plot_padding
Padding at the start and end of the graph (number)
Default value: 10
right_padding
Set a custom right spacing. If not specified, a padding of 20 will be used (number)
Default value: false
show_ticks
Show the tick marks along the x and y axes
Default value: true
show_horizontal_labels
Show the horizontal axis and gridline (boolean)
Default value: true
show_horizontal_grid
Show the horizontal grid lines (boolean)
Default value: true
show_vertical_grid
Show the vertical grid lines (boolean)
Default value: true
show_vertical_labels
Show the vertical axis and gridlines (boolean)
Default value: true
vertical_label_unit
Append a unit to the vertical axis and text in the hover (string)
Default value: empty
watermark
Add in an image to be used as watermark. (link to image or image element)
Default value: false
watermark_location
Where the watermark should be placed. default is the bottom right, can be placed in the center with "middle" (string)
Default value: bottom right
width
Specify the width of the element (number)
Default value: width of $(element)

Line graphs

Line graph with the default rendering (no options):

var linegraph = new Grafico.LineGraph($('linegraph'), { workload: [8, 10, 6, 12, 7, 6, 9] });

Line graph with custom options:

var linegraph2 = new Grafico.LineGraph($('linegraph2'), { workload: [0, 0, 8, 10, 6, 12, 7] },
{
  grid :                  true,
  plot_padding :          0,
  curve_amount :          0,
  start_at_zero :         false,
  stroke_width :          3,
  label_rotation :        -30,
  font_size :             11,
  vertical_label_unit :   "hr",
  colors :                {workload: '#4b80b6'},
  background_color :      "#fff",
  label_color :           "#444",
  grid_color :            "#ccf",
  markers :               "value",
  meanline :              { 'stroke-width': '2px', stroke: '#000' },
  draw_axis :             false,
  labels :                ['mon', '', 'wed', '', 'fri', '', 'sun'],
  hide_empty_label_grid : true,
  datalabels :            {workload:function(idx, value) {
	return ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'][idx] + " : " + value;
  }},
});

Line graph with multiple lines and a watermark:

var linegraph3 = new Grafico.LineGraph($('linegraph3'),
{
  workload:       [8, 10, 6, 12,7, 6, 9],
  your_workload:  [6, 8,  4, 8, 12,6, 2],
  his_workload:   [2, 9,  12,7, 8, 9, 8]
},
{
  markers:            "circle",
  hover_color:        "#000",
  hover_text_color:   "#fff",
  watermark:          "Screenshot.png",
  watermark_location: "middle",
  draw_hovers:        true,
  datalabels: {
    workload:         "My workload",
    your_workload:    "Your workload",
    his_workload:     "His workload"
  }
});

Line graph with multiple lines and negative values:

var linegraph4 = new Grafico.LineGraph($('linegraph4'),
{
  a : [8, -10, 6, 12,7, -6, -9],
  b : [6, 8,  -4, 8, -12,6, 2],
  c : [2, 9,  12,7, 8, -9, 8]
});

.

Line graph options:

curve_amount
Specify the curvature of linegraphs. 0 is hard edges (number)
Default value: 10
markers
Display markers on the datapoint. (string)
Possible options:
  • "circle" - displays a circle
  • "value" - displays a hover with the value
Default value: false
marker_size
The size of the marker (number)
Default value: 0 (smartly chosen)
hide_empty_label_grid
Hide the vertical gridlines for all empty label on the horizontal axis. (boolean)
Default value: false
hover_radius
Set a default height in pixels that represent the activation zone for hover effect (int)
Default value: 15
start_at_zero
If false, Grafico will not start drawing untill the value of a line graph becomes more than zero. (boolean)
Default value: true
stroke_width
Specify the width of the lines in pixels (number)
Default value: 5

Area graphs

Area graphs only support positive ranges.

Area graph with the default rendering (no options):

var areagraph = new Grafico.AreaGraph($('areagraph'), { workload: [8, 10, 6, 12, 7, 6, 9] });

Area graph with custom options:

var areagraph2 = new Grafico.AreaGraph($('areagraph2'),
{ workload: [8, 10, 6, 12, 7, 6, 9] },
{
  grid :                  true,
  area_opacity :          0.5,
  plot_padding :          0,
  font_size :             11,
  vertical_label_unit :   "hr",
  colors :                { workload: '#4b80b6' },
  background_color :      "#fff",
  label_color :           "#444",
  grid_color :            "#ccf",
  markers :               "value",
  meanline :              { 'stroke-width': '2px', stroke: '#000' },
  draw_axis :             false,
  labels :                ['monday', '', 'wednesday', '', 'friday', '', 'sunday'],
  datalabels :            { workload: 'My workload' },
  label_max_size :        4
});

Area graph with multiple areas:

var areagraph3 = new Grafico.AreaGraph($('areagraph3'),
{
  workload:       [8, 10,  6, 12,  7, 6, 9],
  your_workload:  [6,  8,  4,  8, 12, 6, 2],
  his_workload:   [2,  9, 12,  7,  8, 9, 8]
});

Area graph with multiple areas and custom options:

var areagraph4 = new Grafico.AreaGraph($('areagraph4'),
{
  workload:       [8, 10,  6, 12,  7, 6, 9],
  your_workload:  [6,  8,  4,  8, 12, 6, 2],
  his_workload:   [2,  9, 12,  7,  8, 9, 8]
},
{
  markers :                 "value",
  grid :                    false,
  draw_axis :               false,
  plot_padding :            0,
  stroke_width :            5,
  show_vertical_labels :    false,
  show_horizontal_labels :  false,
  hover_color :             "#000",
  hover_text_color :        "#fff",
  datalabels : {
    workload:       "My workload",
    your_workload:  "Your workload",
    his_workload:   "His workload"
  }
});

Area graph options

area_opacity
Set a specific opacity for the areas. If none is given, single areas will be opaque, and multiple will get an opacity of 1.5/number-of-areas. (number between 0 and 1)
Default value: false
markers
Line graph: display markers on the datapoint. (string)
Possible options:
  • "circle" - displays a circle
  • "value" - displays a hover with the value
Default value: false
marker_size
The size of the marker (number)
Default value: 5
hide_empty_label_grid
Hide the vertical gridlines for all empty label on the horizontal axis. (boolean)
Default value: false
start_at_zero
If false, Grafico will not start drawing untill the value of a line graph becomes more than zero. (boolean)
Default value: true
stroke_width
Specify the width of the lines in pixels (number)
Default value: 0

Stacked area graphs

Stacked area graphs only support positive ranges.

Stack graph:

var stackgraph = new Grafico.StackGraph($('stackgraph'),
{
  workload:       [8, 10,  6, 1,  7, 6, 9],
  your_workload:  [6,  8,  4, 1, 12, 6, 2],
  his_workload:   [2,  9, 12, 2,  8, 9, 8]
});

Stack graph with custom options:

var stackgraph2 = new Grafico.StackGraph($('stackgraph2'),
{
  workload:       [8, 10,  6, 1,  7, 6, 9],
  your_workload:  [6,  8,  4, 1, 12, 6, 2],
  his_workload:   [2,  9, 12, 2,  8, 9, 8]
},
{
  markers :           "value",
  draw_axis :         false,
  plot_padding :      0,
  hover_text_color :  "#fff",
  background_color :  "#fff",
  datalabels: {
    workload:       "My workload",
    your_workload:  "Your workload",
    his_workload:   "His workload"
  }
});

Stack line graph:

var stackgraph3 = new Grafico.StackGraph($('stackgraph3'),
{
  workload:       [8, 10,  6, 1,  7, 6, 9],
  your_workload:  [6,  8,  4, 1, 12, 6, 2],
  his_workload:   [2,  9, 12, 2,  8, 9, 8]
},
{
  stacked_fill : false,
  markers : "value"
});

Stacked area graph options

markers
Line graph: display markers on the datapoint. (string)
Possible options:
  • "circle" - displays a circle
  • "value" - displays a hover with the value
Default value: false
marker_size
The size of the marker (number)
Default value: 5
hide_empty_label_grid
Hide the vertical gridlines for all empty label on the horizontal axis. (boolean)
Default value: false
stacked_fill
Specify if the stacked areas should be filled areas or lines (boolean)
Default value: true
start_at_zero
If false, Grafico will not start drawing untill the value of a line graph becomes more than zero. (boolean)
Default value: true
stroke_width
Specify the width of the lines in pixels, only used if stacked_fill is false. (number)
Default value: 5

Stream graphs

Stream graphs are a special kind of stack graphs designed to show large amounts of volitile data, especially trends. The implementation is based on this paper.

Simple stream graph:

var streamgraph = new Grafico.StreamGraph($('streamgraph'),
{
  workload:       [8, 10,  6, 1,  7, 6, 9],
  your_workload:  [6,  8,  4, 1, 12, 6, 2],
  his_workload:   [2,  9, 12, 2,  8, 9, 8]
});

Example with labels:

var streamgraph2 = new Grafico.StreamGraph($('streamgraph2'),
{
  ie6:            [10, 9, 5, 3, 2, 1, 1],
  firefox:        [ 0, 2, 4, 4, 5, 5, 5],
  chrome:         [ 0, 0, 0, 0, 1, 3, 3]
},
{
  datalabels: {
    ie:      "Internet Explorer",
    firefox: "Mozilla Firefox",
    chrome:  "Google Chrome"
  }
});

More complex stream graph:

The label for Harry Potter is not shown, as it does not reach the label threshold.

var streamgraph = new Grafico.StreamGraph($('streamgraph3'),
{
  movie1: [30, 33, 20, 10,  5,  3,  2,  1,  0,  0,  0,  0,  0,  0,  0,  0],
  movie2: [10, 15, 25, 28, 29, 26, 20, 10,  3,  1,  1,  0,  0,  0,  0,  0],
  movie3: [ 0,  4,  6,  8, 11, 13, 11,  9,  3,  0,  0,  0,  0,  0,  0,  0],
  movie4: [ 0,  0,  0,  1,  4,  9, 19, 28, 35, 44, 45, 45, 35, 18,  6,  3],
  movie5: [ 0,  0,  0,  0,  0,  0,  0,  1,  2,  2,  8, 20, 26, 29, 30, 31]
},
{
  stream_line_smoothing: 'simple',
  stream_smart_insertion: true,
  stream_label_threshold: 20,
  datalabels: {
    movie1: "James Bond",
    movie2: "Bourne Ultimatum",
    movie3: "Harry Potter",
    movie4: "Kill Bill",
    movie5: "Return of the Mummie"
  }
}
});

Stream graph options

stream_label_threshold
Minimum value for a stream to have it's label shown. Note that labels are automatically shown when the datalabels are defined. Default value: 0
stream_line_smoothing
Different algorithms for line smoothing. (string)
Possible options:
  • "simple" - simple smoothener of data
  • "weighted" - weights the thickness of data (not yet implemented)
Default value: false
stream_smart_insertion
Tries to determine a smart order for data based on the first moment a dataset becomes larger than 0.
Default value: false

Bar graphs

Bar graph:

var bargraph = new Grafico.BarGraph($('bargraph'), [31, 12, 12, 10, 6, 4, 26]);

Bar graph with custom options:

var bargraph2 = new Grafico.BarGraph($('bargraph2'),
[31, 12, 12, 10, 6, 4, 26],
{
  labels :              ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul"],
  color :               '#4b80b6',
  meanline :            true,
  label_rotation :      -30,
  vertical_label_unit : "%",
  bargraph_lastcolor :  "#666666",
  hover_color :         "#006677",
  datalabels :          {one: ["January", "February", "March", "April", "May", "June", "July"]}
});

Bar graph with negative values: Negative (horizontal) bargraphs require raphael 1.4+ in IE

var bargraph = new Grafico.BarGraph($('bargraph3'),
[31, 12, -12, -10, 6, -4, 26],
{
  labels:                   ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul"],
  color:                    '#4b80b6',
  meanline :                true,
  hover_color :             "#006677",
  bargraph_negativecolor : "#660000",
  datalabels :              {one: ["January", "February", "March", "April", "May", "June", "July"]}
});

Bar graph options

bargraph_lastcolor
Select a different color for the last bar in a bargraph (string, example: "#fff")
Default value: false
bargraph_negativecolor
Select a different color for negative values in a bargraph (string, example: "#fff")
Default value: false
color
Select the color for the bars (string)
Default value: random color

Stacked bar graphs

Stacked bar graphs only support positive ranges.

Stacked Bar graph:

var stackbargraph = new Grafico.StackedBarGraph($('stackbargraph'), {
  a: [31, 12, 12, 10,  6,  4, 26],
  b: [20,  4, 12, 21, 15, 16,  5]
});

Stacked Bar graph with custom options:

var stackedbargraph2 = new Grafico.StackedBarGraph($('stackbargraph2'),
  {
    workload:       [8, 10,  6, 12,  7, 6, 9],
    your_workload:  [6,  8,  4,  8, 12, 6, 2],
    his_workload:   [2,  9, 12,  7,  8, 9, 8]
  },
  {
    labels:               ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul"],
    colors:               {
      workload:       '#f60',
      your_workload:  '#5f3',
      his_workload:   '#08c'
    },
    show_ticks:           false,
    hover_color:          "#CC0000",
    datalabels:           {
      workload:       ["8hrs", "10hrs", "6hrs", "12hrs", "7hrs",  "6hrs", "9hrs"],
      your_workload:  ["6hrs", "8hrs",  "4hrs", "8hrs",  "12hrs", "6hrs", "2hrs"],
      his_workload:   ["2hrs", "9hrs", "12hrs", "7hrs",  "8hrs",  "9hrs", "8hrs"]
    },
  });
});

Stacked Bar graph options

no specific options.

Horizontal bar graphs

Horizontal Bar graph:

var horizgraph = new Grafico.HorizontalBarGraph($('horizgraph'), [30, 12, 12, 10, 6, 4, 26]);

Horizontal Bar graph with custom options:

var horizgraph2 = new Grafico.HorizontalBarGraph($('horizgraph2'),
[30, 12, 12, 10, 6, 4, 26],
{
  horizontal_rounded :  true,
  draw_axis :           false,
  grid :                false,
  label_rotation :      -30,
  color :              '#4b80b6',
  meanline :            true,
  vertical_label_unit : "%",
  bargraph_lastcolor : "#666666",
  hover_color :        "#006677",
  labels :              ["January", "February", "March", "April", "May", "June", "July"],
  datalabels :          {one:["January", "February", "March", "April", "May", "June", "July"]},
  label_max_size :      5
});

Horizontal Bar graph with negative values

var horizgraph = new Grafico.HorizontalBarGraph($('horizgraph3'),
[30, -12, 12, 10, -6, -4, 26],
{
  bargraph_negativecolor:"#f00",
  horizontal_rounded:true,
  datalabels: {one:["January", "February", "March", "April", "May", "June", "July"]}
});

Horizontal bar options

bargraph_lastcolor
Select a different color for the last bar in a bargraph (string, example: "#fff")
Default value: false
bargraph_negativecolor
Select a different color for negative values in a bargraph (string, example: "#fff")
Default value: false
color
Select the color for the bars (string)
Default value: random color
horizontal_rounded
Round the ends of horizontal bar graphs (boolean)
Default value: false

Sparkline

Sparkline:

var sparkline = new Grafico.SparkLine($('sparkline1'), [30, 12, 12, 10, 6, 4, 26]);

Sparkline with custom options:

var sparkline2 = new Grafico.SparkLine($('sparkline2'),
[30, 12, 12, 10, 6, 4, 26],
{
  stroke_width:      3,
  color:             '#4b80b6',
  highlight:         { index: 2, color: "#f00" },
  acceptable_range:  [10,20],
  background_color:  "#ddd"
});

Sparkline with negative values:

var sparkline = new Grafico.SparkLine($('sparkline3'),
[30, 12, -12, -10, 6, 4, 26]
{
  zeroline: true
});

Sparkline options

acceptable_range
draws the background between two value to denote an acceptable range (array, example: [0,10])
Default value: false, needs an explicit background color
color
Set the color (string)
Default value: random color
highlight
draw a circle on one of the datapoints (object, example: {index: 2, color: "#f00"})
color is the color of the circle, index is the datapoint to be highlighted (zero-based)
Default value: false, setting it to true will draw a red dot on the last datapoint.
stroke_width
specify the width of the sparkline in pixels (number)
Default value: 1
zeroline
Display a line on the zero line. Accepts all Raphael parameters (object or boolean, example: { 'stroke-width': '1px', stroke: '#000' }) Default value: false, setting it to true will draw a 1px grey line.

Sparkbar

Sparkbar:

var sparkbar = new Grafico.SparkBar($('sparkbar1'), [30, 12, 12, 10, 6, 4, 26]);

SparkBar with custom options:

var sparkbar2 = new Grafico.SparkBar($('sparkbar2'),
[30, 12, 12, 10, 6, 4, 26],
{
  color :            '#4b80b6',
  acceptable_range :  [0,20],
  background_color : "#ddd",
  bargraph_lastcolor: "#000"
});

Sparkbar with negative values:

var sparkbar3 = new Grafico.SparkBar($('sparkbar3'),
[30, -12, 12, -10, -6, -4, 26],
{
  zeroline : true,
  bargraph_negativecolor : "#660"
});

Sparkbar options

acceptable_range
draws the background between two value to denote an acceptable range (array, example: [0,10])
Default value: false, needs an explicit background color
bargraph_lastcolor
select a different color for the last bar in a bargraph (string, example: "#fff")
Default value: false
bargraph_negativecolor
select a different color for negative values in a bargraph (string, example: "#fff")
Default value: false
color
Set the color (string)
Default value: random color
zeroline
Display a line on the zero line. Accepts all Raphael parameters (object or boolean, example: { 'stroke-width': '1px', stroke: '#000' }) Default value: false, setting it to true will draw a 1px grey line.

Sparkarea

SparkArea:

var sparkarea = new Grafico.SparkArea($('sparkarea1'), [30, 12, 12, 10, 6, 4, 26, 12, 12, 10, 6, 4, 26, 12, 12, 10, 6, 4, 26, 12, 12, 10, 6, 4, 26, 12, 12, 10, 6, 4, 26, 12, 12, 10, 6, 4, 26, 12, 12, 10, 6, 4, 26, 12, 12, 10, 6, 4, 26]);

Sparkarea with custom options:

var sparkarea2 = new Grafico.SparkArea($('sparkarea2'),
[30, 12, 12, 10, 6, 4, 26, 12, 12, 10, 6, 4, 26, 12, 12, 10, 6, 4, 26, 12, 12, 10, 6, 4, 26, 12, 12, 10, 6, 4, 26, 12, 12, 10, 6, 4, 26, 12, 12, 10, 6, 4, 26, 12, 12, 10, 6, 4, 26],
{
  stroke_width : 1,
  color: ['#4b80b6',"#ddd"],
  highlight: {index: 20, color: "#f00"},
});

Sparkarea options

acceptable_range
draws the background between two value to denote an acceptable range (array, example: [0,10])
Default value: false, needs an explicit background color
color
Set the color. If given an array, the first value will be used for the stroke and the second for the area. If given a string, it will be used for both, with the area being given 0.2 opacity. (string or array)
Default value: random color
highlight
draw a circle on one of the datapoints (object, example: {index: 2, color: "#f00"})
color is the color of the circle, index is the datapoint to be highlighted (zero-based)
Default value: false, setting it to true will draw a red dot on the last datapoint.
stroke_width
specify the width of the sparkline in pixels (number)
Default value: 1
zeroline
Display a line on the zero line. Accepts all Raphael parameters (object or boolean, example: { 'stroke-width': '1px', stroke: '#000' }) Default value: false, setting it to true will draw a 1px grey line.