RGraph: HTML5 canvas graph library - Bar chart documentation

The bar graph, along with the line chart, is probably the most configurable of all the charts available, simply because it's more common, and hence, I've worked on it the most.

The example file is here.

    window.onload = function ()
        var data = [280,45,133,166,84,259,266,960,219,311];
        var bar = new RGraph.Bar('myCanvas', data);
        bar.Set('chart.labels', ['Richard', 'Alex', 'Nick', 'Scott', 'Kjnell', 'Doug', 'Charles', 'Michelle', 'Mark', 'Alison']);
        bar.Set('chart.gutter', 45);
        bar.Set('chart.background.barcolor1', 'rgba(255,255,255,1)');
        bar.Set('chart.background.barcolor2', 'rgba(255,255,255,1)');
        bar.Set('chart.background.grid', true);
        bar.Set('chart.colors', ['rgba(255,0,0,1)']);

Available properties

You can use these properties to control how the bar graph apears. You can set them by using the Set() method. Eg:

myBar.Set('name', 'value');

chart.background.barcolor1 The color of the background bars, (1 of 2).
Default: white
chart.background.barcolor2 The color of the background bars, (2 of 2).
Default: white
chart.background.grid Whether to show the background grid or not.
Default: true
chart.background.grid.color The color of the background grid.
Default: #ddd
chart.background.grid.hsize The horizontal background grid size.
Default: 40
chart.background.grid.vsize The vertical background grid size.
Default: 18
chart.background.grid.width The width that the background grid lines are. Decimals (eg 0.5) are permitted.
Default: 1
chart.background.hbars An array of information stipulating horizontal coloured bars. You can use these to indicate limits. Eg: myBar.Set('hbars', [[75, 10, 'yellow'], [85, 15, 'red']]); This would give you two bars, one red and a lower yellow bar. The units correspond to your scale, and are the starting point and the height.
Default: null
chart.background.grid.border Determines whether a border line is drawn around the grid.
Default: true
chart.background.grid.hlines Determines whether to draw the horizontal grid lines.
Default: true
chart.background.grid.vlines Determines whether to draw the vertical grid lines.
Default: true
chart.strokecolor The color of the outline of the bars.
Default: #666
chart.colors An array of the colors of the actual bars.
Default: An array - ['rgb(0,0,255)', '#0f0', '#00f', '#ff0', '#0ff', '#0f0']
chart.hmargin The horizontal margin (in pixels) of the graph. This is inside the left axis.
Default: 5
chart.line Formerly a boolean, this now stipulates a line graph object which is to be drawn on top of the bar chart. You can see an example here.
Default: null
chart.gutter The gutter of the graph. This is the area outside of the X and Y axis - where the labels go. If you're short on space for your labels, try increasing this.
Default: 25
chart.labels An array of the labels to be used on the graph.
Default: An empty array
chart.xaxispos The position of the X axis. This can be bottom or center.
Default: bottom
chart.axis.color The color of the axes.
Default: black
chart.text.color The color of the labels.
Default: black
chart.text.size The size (in points) of the labels.
Default: 10
chart.text.angle The angle of the horizontal text labels (at the bottom of the graph). This can be one of three values - 0, 45 or 90.
Default: 0 (Horizontal)
chart.text.font The font used to render the text.
Default: Verdana
chart.ymax The optional maximum Y scale value. If not specified then it will be calculated.
Default: null (It's calculated)
chart.tooltips A numerically indexed array of tooltips that are shown when a bar is clicked. These can contain HTML.
Default: An empty array
chart.grouping How the bars are grouped, and it should be one of: grouped or stacked
Default: grouped
chart.title The title of the graph, if any.
Default: null
chart.title.color The color of the title.
Default: black
chart.title.vpos This allows you to completely override the vertical positioning of the title. It should be a number between 0 and 1, and is multiplied with the gutter and then used as the vertical position. It can be useful if you need to have a large gutter.
Default: null
chart.shadow Whether a drop shadow is applied.
Default: false
chart.shadow.color The color of the shadow.
Default: #666
chart.shadow.offsetx The X offset of the shadow.
Default: 3
chart.shadow.offsety The Y offset of the shadow.
Default: 3
chart.shadow.blur The severity of the shadow blurring effect.
Default: 3
chart.scale.decimals The number of decimal places to display for the Y scale.
Default: 0
chart.key An array of key information.
Default: [] (An empty array)
chart.key.background The colour of the key background. Typically white, you could set this to something like rgba(255,255,255,0.7) to allow people to see things behind it.
Default: white
chart.key.position Determines the position of the key.Either graph (default), or gutter.
Default: graph
chart.key.shadow Whether a small drop shadow is applied to the key.
Default: false
chart.contextmenu An array of context menu items. More information on context menus is here.
Default: [] (An empty array)
chart.units.pre The units that the Y axis is measured in. This string is displayed BEFORE the actual number, allowing you to specify values such as "$50".
Default: none
chart.units.post The units that the Y axis is measured in. This string is displayed AFTER the actual number, allowing you to specify values such as "50ms".
Default: none
chart.tooltip.effect The animated effect used for showing tooltips. Can be either fade or expand.
Default: fade
chart.variant This simply stipulates whether you want a regular bar chart, a dot chart, a pyramid chart a 3D chart, a sketch or a glassy chart. Possible values are:
  • bar
  • dot
  • pyramid
  • arrow
  • 3d
  • sketch
  • glass
The pyramid, dot, arrow, sketch and glass variants are only effective for regular bar charts - not grouped or stacked charts.
Default: bar
chart.crosshairs If true, you will get a crosshair centering on the current mouse position.
Default: false
chart.crosshairs.color The color of the crosshairs.
Default: #333
chart.annotatable Whether annotations are enabled for the chart (ie you can draw on the chart interactively.
Default: false
chart.annotate.color If you do not allow the use of the palette, then this will be the only colour allowed for annotations.
Default: black
chart.labels.above If true, values will be shown above the bars. For regular and stacked bar charts units are included, whereas for grouped bar charts they're not (usually there isn't enough space for them).
Default: false
chart.ylabels Can be true or false and determines whether the chart has Y axis labels.
Default: true
chart.zoom.mode Can be used to control whether the zoom is in thumbnail or canvas mode. Possible values are: thumbnail and canvas.
Default: canvas
chart.zoom.factor This is the factor that the graph will be zoomed by (bigger values means more zoom)
Default: 1.5
chart.zoom.fade.in Whether the zoomed canvas fades in or not. This also can be used to control the fade in for the zoom in thumbnail mode.
Default: true
chart.zoom.fade.out Whether the zoomed canvas fades out or not. This also can be used to control the fade in for the zoom in thumbnail mode.
Default: true
chart.zoom.hdir The horizontal direction of the zoom. Possible values are: left, center, right
Default: right
chart.zoom.vdir The vertical direction of the zoom. Possible values are: up, center, down
Default: down
chart.zoom.delay The delay (in milliseconds) between frames.
Default: 50
chart.zoom.frames The number of frames in the zoom animation.
Default: 10
chart.zoom.shadow Whether or not the zoomed canvas has a shadow or not.
Default: true
chart.zoom.thumbnail.width When the zoom is in thumbnail mode, this is the width (in pixels) of the thumbnail.
Default: 75
chart.zoom.thumbnail.height When the zoom is in thumbnail mode, this is the height (in pixels) of the thumbnail.
Default: 75