Horizontal Bar chart API reference

Summary: Documentation about the Horizontal Bar chart including information about all of the options that are available to you. The Horizontal Bar chart can be used when you need a different aesthetic for your page or when you have longer labels (which the Horizontal Bar chart is better suited to).

Example

[No canvas support]
<script>
    labels = ['Richard','Gulliver','John'];
    data   = [280,45,133];
    
    // To show a stacked or grouped chart each element of the data array should
    // be an array containing the data to be shown.
    //data = [[120,80,60],[30,12,13],[50,50,33]];

    new RGraph.HBar({
        id: 'cvs',
        data: data,
        options: {
            // grouping: 'stacked',
            
            marginInner: 15,
            
            backgroundBarsColor1: 'white',
            backgroundBarsColor2: 'white',
            backgroundGrid: true,
            backgroundGridHlines: false,
            backgroundGridBorder: false,
            
            colors: ['red','green','blue'],
            
            xaxis: false,
            yaxisLabels: labels,
            yaxisTickmarksCount: 0,
            
            tooltips: '<b>Results:</b><br />%{key}',
            tooltipsFormattedKeyLabels: ['Sales','Sales','Sales'],
            tooltipsCss: {
                fontSize: '16pt',
                backgroundColor: 'black',
                color:'white',
                textAlign: 'left'
            }
        }
    }).draw();
</script>

Properties

You can use these properties to control how the chart appears. You can set them by including them in the options section of the configuration, as shown above.

Background properties

PropertyDescriptionDefault
backgroundBarsCountThe number of background bars.5
backgroundBarsColor1The color of the background bars, (1 of 2).white
backgroundBarsColor2The color of the background bars, (2 of 2).white
backgroundGridWhether to show the background grid or not.true
backgroundGridColorThe color of the background grid.#ddd
backgroundGridLinewidthThe width that the background grid lines are. Decimals (eg 0.5) are permitted.0.5
backgroundGridBorderDetermines whether a border line is drawn around the grid.true
backgroundGridHlinesDetermines whether to draw the horizontal grid lines.true
backgroundGridVlinesDetermines whether to draw the vertical grid lines.true
backgroundGridVlinesCountWhen using autofit this allows you to specify how many vertical grid lines you want.20
backgroundGridDottedIf you want to have your background grid dashed then set this to true.false
backgroundGridDashedIf you want to have your background grid dotted then set this to true. This takes precedence over dashed lines.false
backgroundColorIf you want to have a single background color for your chart you can use this. It doesn't cover the margins. If you want that then you can simply apply a CSS background color to the canvas tag.null
backgroundBarsCount
The number of background bars.
Default: 5

backgroundBarsColor1
The color of the background bars, (1 of 2).
Default: white

backgroundBarsColor2
The color of the background bars, (2 of 2).
Default: white

backgroundGrid
Whether to show the background grid or not.
Default: true

backgroundGridColor
The color of the background grid.
Default: #ddd

backgroundGridLinewidth
The width that the background grid lines are. Decimals (eg 0.5) are permitted.
Default: 0.5

backgroundGridBorder
Determines whether a border line is drawn around the grid.
Default: true

backgroundGridHlines
Determines whether to draw the horizontal grid lines.
Default: true

backgroundGridVlines
Determines whether to draw the vertical grid lines.
Default: true

backgroundGridVlinesCount
When using autofit this allows you to specify how many vertical grid lines you want.
Default: 20

backgroundGridDotted
If you want to have your background grid dashed then set this to true.
Default: false

backgroundGridDashed
If you want to have your background grid dotted then set this to true. This takes precedence over dashed lines.
Default: false

backgroundColor
If you want to have a single background color for your chart you can use this. It doesn't cover the margins. If you want that then you can simply apply a CSS background color to the canvas tag.
Default: null

X axis properties

PropertyDescriptionDefault
xaxisSet this to true if you don't want an X axis.true
xaxisPositionWhether the X axis is shown at the top or at the bottom of the chart - possible values are top and bottom.bottom
xaxisLinewidthThe linewidth of the X axis.1
xaxisColorThe color of the X axis.black
xaxisTickmarksUsing this property you can turn off the X tickmarks.true
xaxisTickmarksCountThis allows you to stipulate how many X axis tickmarks are displayed.null
xaxisTickmarksLengthUse this to stipulate the length of the X axis tickmarks.3
xaxisTickmarksLastLeftWhether the last tickmark on the left-hand-side is shown.null
xaxisTickmarksLastRightWhether the last tickmark on the right-hand-side is shown.null
xaxisLabelsIf you prefer to use labels on the X axis instead of a scale then this should be array of those labels. You can use the xaxisLabelsPosition option to control their positioning.null
xaxisLabelsCountThis determines how many labels are shown on the scale if it's being used instead of textual labels.5
xaxisLabelsAngleIf you want your labels to be at an angle then this is the property to specify it (in degrees). If you use this then you may also need to use the xaxisLabelsOffsety property.0
xaxisLabelsPositionIf you use labels instead of a scale this controls the positioning of them.edge
xaxisLabelsSpecificAlignThis determines the alignment of the specific labels. You probably won't need this.left
xaxisLabelsOffsetxThis allows you finer grained control in the horizontal direction over the X label positioning if you need it.0
xaxisLabelsOffsetyThis allows you finer grained control in the vertical direction over the X label positioning if you need it.0
xaxisLabelsHalignIf desired you can specify the horizontal alignment with this.null
xaxisLabelsValignIf desired you can specify the vertical alignment with this.null
xaxisLabelsFontThe font used for the X axis labels. It defaults to the textFont settingnull
xaxisLabelsSizeThe size of the X axis labels. It defaults to the textSize settingnull
xaxisLabelsBoldWhether the X axis labels are bold or notnull
xaxisLabelsItalicWhether the X axis labels are italic or notnull
xaxisLabelsColorThe color of the X axis labels. It defaults to the main textColor optionnull
xaxisTitleThis allows you to specify a title for the X axis.none
xaxisTitleSizeThis allows you to specify a size for the X axis title.null
xaxisTitleFontThis allows you to specify a font for the X axis title.null
xaxisTitleBoldThis controls whether the X axis title is bold or not.null
xaxisTitleItalicThis controls whether the X axis title is italic or not.null
xaxisTitleColorThis controls the color of the X axis title.null
xaxisTitlePosThis is multiplied with the margin to give the position of the X axis title.0.25
xaxisTitleXBy giving this you can specifically set the X position of the X axis title.null
xaxisTitleYBy giving this you can specifically set the Y position of the X axis title.null
xaxisTitleOffsetxUse this property to adjust the X position of the title.0
xaxisTitleOffsetyUse this property to adjust the Y position of the title.0
xaxisTitleHalignUse this property to specify the horizontal alignment of the title.0
xaxisTitleValignUse this property to specify the vertical alignment of the title.0
xaxisScaleWhether the scale should be drawn or not.true
xaxisScaleUnitsPreThe units that the X axis is measured in. This string is displayed before the actual number, allowing you to specify values such as "$50".none
xaxisScaleUnitsPostThe units that the X axis is measured in. This string is displayed after the actual number, allowing you to specify values such as "50ms".none
xaxisScaleDecimalsThe number of decimal places to display for the X scale.0
xaxisScalePointThe character used as the decimal point..
xaxisScaleThousandThe character used as the thousand separator.,
xaxisScaleRoundWhether to round the maximum scale value up or not. This will produce slightly better scales in some instances.null
xaxisScaleMax(Optional) An optional max figure for the X scale.none (one is calculated)
xaxisScaleMinAn optional minimum figure for the X scale.0
xaxisScaleFormatterThis can be a function, which is passed the object and the number and should return a formatted number (formatted as you wish).
function myFormatter(opt)
{
    var obj = opt.object,
        num = opt.number;

    return num + 'F'; // An example of formatting
}
null
xaxis
Set this to true if you don't want an X axis.
Default: true

xaxisPosition
Whether the X axis is shown at the top or at the bottom of the chart - possible values are top and bottom.
Default: bottom

xaxisLinewidth
The linewidth of the X axis.
Default: 1

xaxisColor
The color of the X axis.
Default: black

xaxisTickmarks
Using this property you can turn off the X tickmarks.
Default: true

xaxisTickmarksCount
This allows you to stipulate how many X axis tickmarks are displayed.
Default: null

xaxisTickmarksLength
Use this to stipulate the length of the X axis tickmarks.
Default: 3

xaxisTickmarksLastLeft
Whether the last tickmark on the left-hand-side is shown.
Default: null

xaxisTickmarksLastRight
Whether the last tickmark on the right-hand-side is shown.
Default: null

xaxisLabels
If you prefer to use labels on the X axis instead of a scale then this should be array of those labels. You can use the xaxisLabelsPosition option to control their positioning.
Default: null

xaxisLabelsCount
This determines how many labels are shown on the scale if it's being used instead of textual labels.
Default: 5

xaxisLabelsAngle
If you want your labels to be at an angle then this is the property to specify it (in degrees). If you use this then you may also need to use the xaxisLabelsOffsety property.
Default: 0

xaxisLabelsPosition
If you use labels instead of a scale this controls the positioning of them.
Default: edge

xaxisLabelsSpecificAlign
This determines the alignment of the specific labels. You probably won't need this.
Default: left

xaxisLabelsOffsetx
This allows you finer grained control in the horizontal direction over the X label positioning if you need it.
Default: 0

xaxisLabelsOffsety
This allows you finer grained control in the vertical direction over the X label positioning if you need it.
Default: 0

xaxisLabelsHalign
If desired you can specify the horizontal alignment with this.
Default: null

xaxisLabelsValign
If desired you can specify the vertical alignment with this.
Default: null

xaxisLabelsFont
The font used for the X axis labels. It defaults to the textFont setting
Default: null

xaxisLabelsSize
The size of the X axis labels. It defaults to the textSize setting
Default: null

xaxisLabelsBold
Whether the X axis labels are bold or not
Default: null

xaxisLabelsItalic
Whether the X axis labels are italic or not
Default: null

xaxisLabelsColor
The color of the X axis labels. It defaults to the main textColor option
Default: null

xaxisTitle
This allows you to specify a title for the X axis.
Default: none

xaxisTitleSize
This allows you to specify a size for the X axis title.
Default: null

xaxisTitleFont
This allows you to specify a font for the X axis title.
Default: null

xaxisTitleBold
This controls whether the X axis title is bold or not.
Default: null

xaxisTitleItalic
This controls whether the X axis title is italic or not.
Default: null

xaxisTitleColor
This controls the color of the X axis title.
Default: null

xaxisTitlePos
This is multiplied with the margin to give the position of the X axis title.
Default: 0.25

xaxisTitleX
By giving this you can specifically set the X position of the X axis title.
Default: null

xaxisTitleY
By giving this you can specifically set the Y position of the X axis title.
Default: null

xaxisTitleOffsetx
Use this property to adjust the X position of the title.
Default: 0

xaxisTitleOffsety
Use this property to adjust the Y position of the title.
Default: 0

xaxisTitleHalign
Use this property to specify the horizontal alignment of the title.
Default: 0

xaxisTitleValign
Use this property to specify the vertical alignment of the title.
Default: 0

xaxisScale
Whether the scale should be drawn or not.
Default: true

xaxisScaleUnitsPre
The units that the X axis is measured in. This string is displayed before the actual number, allowing you to specify values such as "$50".
Default: none

xaxisScaleUnitsPost
The units that the X axis is measured in. This string is displayed after the actual number, allowing you to specify values such as "50ms".
Default: none

xaxisScaleDecimals
The number of decimal places to display for the X scale.
Default: 0

xaxisScalePoint
The character used as the decimal point.
Default: .

xaxisScaleThousand
The character used as the thousand separator.
Default: ,

xaxisScaleRound
Whether to round the maximum scale value up or not. This will produce slightly better scales in some instances.
Default: null

xaxisScaleMax
(Optional) An optional max figure for the X scale.
Default: none (one is calculated)

xaxisScaleMin
An optional minimum figure for the X scale.
Default: 0

xaxisScaleFormatter
This can be a function, which is passed the object and the number and should return a formatted number (formatted as you wish).
function myFormatter(opt)
{
    var obj = opt.object,
        num = opt.number;

    return num + 'F'; // An example of formatting
}

Default: null

Y axis properties

PropertyDescriptionDefault
yaxisWhether the Y axis is drawn.true
yaxisLinewidthThe linewidth of the Y axis.1
yaxisColorThe color of the Y axis.black
yaxisPositionSpecifies the Y axis position. Can be left or right.left
yaxisTickmarks.Whether the Y axis tickmarks are drawn.true
yaxisTickmarksLengthThe length of the Y axis tickmarks.3
yaxisTickmarksCountThis allows you to stipulate how many Y axis tickmarks there are.null (related to how many labels there are)
yaxisTickmarksLastTopWhether the top-most tickmark is drawn.null (displayed if the X axis position warrants it)
yaxisTickmarksLastBottomWhether the bottom-most tickmark is drawn.null (displayed if the X axis position warrants it)
yaxisLabelsGive this property an array of your labels that want to appear on your chart.null
yaxisLabelsPositionThis controls how the specific labels are positioned on the Y axis. Typically you wouldn't use for a Horizontal Bar chart.edge
yaxisLabelsOffsetxThis allows you finer grained control in the horizontal direction over the Y label positioning if you need it.0
yaxisLabelsOffsetyThis allows you finer grained control in the vertical direction over the Y label positioning if you need it.0
yaxisLabelsFontThe font that's used by the Y axis labels.null
yaxisLabelsSizeThe size of the Y axis labels.null
yaxisLabelsColorThe color of the Y axis labels.null
yaxisLabelsBoldWhether the Y axis labels are bold or not.null
yaxisLabelsItalicWhether the Y axis labels are italic or not.null
yaxisLabelsHalignThe horizontal alignment of the Y axis labels.null
yaxisLabelsValignThe vertical alignment of the Y axis labels.null
yaxisTitleThis allows you to specify a title for the Y axis.none
yaxisTitleSizeThis allows you to specify a size for the Y axis title.null
yaxisTitleFontThis allows you to specify a font for the Y axis title.null
yaxisTitleBoldThis controls whether the Y axis title is bold or not.null
yaxisTitleColorThis controls what color the Y axis title is.null
yaxisTitleItalicThis controls whether the Y axis title is italic or not.null
yaxisTitlePosThis is multiplied with the margin to give the position of the Y axis title.0.25
yaxisTitleOffsetxThe pixel offset that's added to the Y axis titles X coordinate.0
yaxisTitleOffsetyThe pixel offset that's added to the Y axis titles Y coordinate.0
yaxisTitleXBy giving this you can specifically set the X position of the Y axis title.null
yaxisTitleYBy giving this you can specifically set the Y position of the Y axis title.null
yaxisTitleHalignThe horizontal alignment of the Y axis title.0
yaxisTitleValignThe vertical alignment of the Y axis title.0
yaxisTitleAccessibleWith this property you can control whether the Y axis title is accessible or not.true
yaxis
Whether the Y axis is drawn.
Default: true

yaxisLinewidth
The linewidth of the Y axis.
Default: 1

yaxisColor
The color of the Y axis.
Default: black

yaxisPosition
Specifies the Y axis position. Can be left or right.
Default: left

yaxisTickmarks.
Whether the Y axis tickmarks are drawn.
Default: true

yaxisTickmarksLength
The length of the Y axis tickmarks.
Default: 3

yaxisTickmarksCount
This allows you to stipulate how many Y axis tickmarks there are.
Default: null (related to how many labels there are)

yaxisTickmarksLastTop
Whether the top-most tickmark is drawn.
Default: null (displayed if the X axis position warrants it)

yaxisTickmarksLastBottom
Whether the bottom-most tickmark is drawn.
Default: null (displayed if the X axis position warrants it)

yaxisLabels
Give this property an array of your labels that want to appear on your chart.
Default: null

yaxisLabelsPosition
This controls how the specific labels are positioned on the Y axis. Typically you wouldn't use for a Horizontal Bar chart.
Default: edge

yaxisLabelsOffsetx
This allows you finer grained control in the horizontal direction over the Y label positioning if you need it.
Default: 0

yaxisLabelsOffsety
This allows you finer grained control in the vertical direction over the Y label positioning if you need it.
Default: 0

yaxisLabelsFont
The font that's used by the Y axis labels.
Default: null

yaxisLabelsSize
The size of the Y axis labels.
Default: null

yaxisLabelsColor
The color of the Y axis labels.
Default: null

yaxisLabelsBold
Whether the Y axis labels are bold or not.
Default: null

yaxisLabelsItalic
Whether the Y axis labels are italic or not.
Default: null

yaxisLabelsHalign
The horizontal alignment of the Y axis labels.
Default: null

yaxisLabelsValign
The vertical alignment of the Y axis labels.
Default: null

yaxisTitle
This allows you to specify a title for the Y axis.
Default: none

yaxisTitleSize
This allows you to specify a size for the Y axis title.
Default: null

yaxisTitleFont
This allows you to specify a font for the Y axis title.
Default: null

yaxisTitleBold
This controls whether the Y axis title is bold or not.
Default: null

yaxisTitleColor
This controls what color the Y axis title is.
Default: null

yaxisTitleItalic
This controls whether the Y axis title is italic or not.
Default: null

yaxisTitlePos
This is multiplied with the margin to give the position of the Y axis title.
Default: 0.25

yaxisTitleOffsetx
The pixel offset that's added to the Y axis titles X coordinate.
Default: 0

yaxisTitleOffsety
The pixel offset that's added to the Y axis titles Y coordinate.
Default: 0

yaxisTitleX
By giving this you can specifically set the X position of the Y axis title.
Default: null

yaxisTitleY
By giving this you can specifically set the Y position of the Y axis title.
Default: null

yaxisTitleHalign
The horizontal alignment of the Y axis title.
Default: 0

yaxisTitleValign
The vertical alignment of the Y axis title.
Default: 0

yaxisTitleAccessible
With this property you can control whether the Y axis title is accessible or not.
Default: true

Margin properties

PropertyDescriptionDefault
marginLeftThe left margin of the chart, (the margin is where the labels and title are)).75
marginLeftAutoIf set to true this will automatically size the left margin to accommodate your labels).true
marginRightThe right margin of the chart, (the margin is where the labels and title are).35
marginRightAutoIf set to true this will automatically size the right margin to accommodate your labels).false
marginTopThe top margin of the chart, (the margin is where the labels and title are).35
marginBottomThe bottom margin of the chart, (the margin is where the labels and title are).35 (in 3D charts if you leave this at 25 it will change to 80)
marginInnerThe vertical margin that is applied to each individual bar.3
marginLeft
The left margin of the chart, (the margin is where the labels and title are)).
Default: 75

marginLeftAuto
If set to true this will automatically size the left margin to accommodate your labels).
Default: true

marginRight
The right margin of the chart, (the margin is where the labels and title are).
Default: 35

marginRightAuto
If set to true this will automatically size the right margin to accommodate your labels).
Default: false

marginTop
The top margin of the chart, (the margin is where the labels and title are).
Default: 35

marginBottom
The bottom margin of the chart, (the margin is where the labels and title are).
Default: 35 (in 3D charts if you leave this at 25 it will change to 80)

marginInner
The vertical margin that is applied to each individual bar.
Default: 3

Color properties

PropertyDescriptionDefault
colorsAn array of the colors of the bars.['rgb(0,0,255)', '#0f0', '#00f', '#ff0', '#0ff', '#0f0']
colorsStrokeThe color of the outlines of the bars.black
colorsSequentialIf true, for regular bar charts, the colors that you specify will be used in a sequential fashion.false
colors
An array of the colors of the bars.
Default: ['rgb(0,0,255)', '#0f0', '#00f', '#ff0', '#0ff', '#0f0']

colorsStroke
The color of the outlines of the bars.
Default: black

colorsSequential
If true, for regular bar charts, the colors that you specify will be used in a sequential fashion.
Default: false

Other label properties

PropertyDescriptionDefault
labelsAboveThis is a boolean which if true, will cause labels to be shown to the right of the bars. (It's called "above" for API compatibility).false
labelsAboveDecimalsThis is a number which controls how many decimals are shown. It defaults to 0, and since it was added (4th December 2010) you may need to set this, otherwise no decimals will be shown.0
labelsAbovePointThe character used for the decimal point..
labelsAboveThousandThe character used for the thousand separator.,
labelsAboveUnitsPreIf you wish you can specify units that are prepended to the text label (separately to the main xaxisScaleUnitsPre setting)null
labelsAboveUnitsPostIf you wish you can specify units that are appended to the text label (separately to the main xaxisScaleUnitsPost setting)null
labelsAboveFontThe font used for the above labels. It defaults to the textFont settingnull
labelsAboveSizeThe size of the above labels. It defaults to the textSize settingnull
labelsAboveBoldWhether the above labels are bold or notnull
labelsAboveItalicWhether the above labels are italic or notnull
labelsAboveColorThe color of the above labels. It defaults to the main textColor optionnull
textFontThe font used to render the text.Arial, Verdana, sans-serif
textColorThe color of the labels.black
textSizeThe size (in points) of the labels.12
textBoldWhether the text is bold or not.false
textItalicWhether the text is italic or not.false
textAccessibleA new feature in 2016 that allows you to use DOM text in place of canvas text. It makes for much higher quality text that you can also select if desired (for copy/paste operations). It won't fit all situations and you can read more about the DOM text feature here. A good way to control borders/margins/padding etc is not to set them on the canvas but to wrap the canvas in a div and set them on that like this:
<div style="margin-left: 50px; display: inline-block">
<canvas id="cvs" width="650" height="250"></canvas>
</div>
true
textAccessibleOverflowThis can be visible or hidden and it controls whether the text is clipped to the edges of the canvas. It defaults to be visible and means you can set small margins if you wish.visible
textAccessiblePointereventsThis controls whether the DOM text responds to mouse based events or not (it sets the pointer-events CSS property to none).true
labelsAbove
This is a boolean which if true, will cause labels to be shown to the right of the bars. (It's called "above" for API compatibility).
Default: false

labelsAboveDecimals
This is a number which controls how many decimals are shown. It defaults to 0, and since it was added (4th December 2010) you may need to set this, otherwise no decimals will be shown.
Default: 0

labelsAbovePoint
The character used for the decimal point.
Default: .

labelsAboveThousand
The character used for the thousand separator.
Default: ,

labelsAboveUnitsPre
If you wish you can specify units that are prepended to the text label (separately to the main xaxisScaleUnitsPre setting)
Default: null

labelsAboveUnitsPost
If you wish you can specify units that are appended to the text label (separately to the main xaxisScaleUnitsPost setting)
Default: null

labelsAboveFont
The font used for the above labels. It defaults to the textFont setting
Default: null

labelsAboveSize
The size of the above labels. It defaults to the textSize setting
Default: null

labelsAboveBold
Whether the above labels are bold or not
Default: null

labelsAboveItalic
Whether the above labels are italic or not
Default: null

labelsAboveColor
The color of the above labels. It defaults to the main textColor option
Default: null

textFont
The font used to render the text.
Default: Arial, Verdana, sans-serif

textColor
The color of the labels.
Default: black

textSize
The size (in points) of the labels.
Default: 12

textBold
Whether the text is bold or not.
Default: false

textItalic
Whether the text is italic or not.
Default: false

textAccessible
A new feature in 2016 that allows you to use DOM text in place of canvas text. It makes for much higher quality text that you can also select if desired (for copy/paste operations). It won't fit all situations and you can read more about the DOM text feature here. A good way to control borders/margins/padding etc is not to set them on the canvas but to wrap the canvas in a div and set them on that like this:
<div style="margin-left: 50px; display: inline-block">
<canvas id="cvs" width="650" height="250"></canvas>
</div>

Default: true

textAccessibleOverflow
This can be visible or hidden and it controls whether the text is clipped to the edges of the canvas. It defaults to be visible and means you can set small margins if you wish.
Default: visible

textAccessiblePointerevents
This controls whether the DOM text responds to mouse based events or not (it sets the pointer-events CSS property to none).
Default: true

Title properties

PropertyDescriptionDefault
titleThe title of the chart, if any.null
titleFontThe font that the title is rendered in. If not specified the textFont setting is used (usually Arial).null
titleSizeThe size of the title. If not specified the size is usually 2pt bigger than the textSize setting.null
titleBoldWhether the title is bold or not.null
titleItalicWhether the title is italic or not.null
titleColorThe color of the title.null
titleBackgroundThe background color (if any) for the title.null
titleXTo give the exact X coordinate for the title - use this. This can also be a string like this: "-5" -- in which case it's converted to a number and added to the calculated coordinate - allowing you to adjust the calculated coordinate.null
titleYTo give the exact Y coordinate for the title - use this. This can also be a string like this: "-5" -- in which case it's converted to a number and added to the calculated coordinate - allowing you to adjust the calculated coordinate.null
titleHalignThe horizontal alignment of the title.center (can change depending on other options)
titleValignThe vertical alignment of the title.center (can change depending on other options)
title
The title of the chart, if any.
Default: null

titleFont
The font that the title is rendered in. If not specified the textFont setting is used (usually Arial).
Default: null

titleSize
The size of the title. If not specified the size is usually 2pt bigger than the textSize setting.
Default: null

titleBold
Whether the title is bold or not.
Default: null

titleItalic
Whether the title is italic or not.
Default: null

titleColor
The color of the title.
Default: null

titleBackground
The background color (if any) for the title.
Default: null

titleX
To give the exact X coordinate for the title - use this. This can also be a string like this: "-5" -- in which case it's converted to a number and added to the calculated coordinate - allowing you to adjust the calculated coordinate.
Default: null

titleY
To give the exact Y coordinate for the title - use this. This can also be a string like this: "-5" -- in which case it's converted to a number and added to the calculated coordinate - allowing you to adjust the calculated coordinate.
Default: null

titleHalign
The horizontal alignment of the title.
Default: center (can change depending on other options)

titleValign
The vertical alignment of the title.
Default: center (can change depending on other options)

Shadow properties

PropertyDescriptionDefault
shadowWhether a small drop shadow is applied.false
shadowColorThe color of the shadow.#666
shadowOffsetxThe X offset of the shadow.3
shadowOffsetyThe Y offset of the shadow.3
shadowBlurThe severity of the shadow blurring effect.3
shadow
Whether a small drop shadow is applied.
Default: false

shadowColor
The color of the shadow.
Default: #666

shadowOffsetx
The X offset of the shadow.
Default: 3

shadowOffsety
The Y offset of the shadow.
Default: 3

shadowBlur
The severity of the shadow blurring effect.
Default: 3

Key properties

The key properties are documented on the key documentation page.

Interactive features properties

PropertyDescriptionDefault
contextmenuAn array of context menu items. You cannot have context menus AND tooltips, only one or the other. More information about context menus is here.[] (An empty array)
tooltipsAn array of tooltips for the chart.An empty array
tooltipsEventThis is the event that triggers the tooltips. It can be click or mousemove.onclick
tooltipsEffectThe effect used for showing tooltips. Can be either fade or none.fade
tooltipsOverrideIf you wish to handle showing tooltips yourself, this should be a function object which does just that. There's more information on the tooltips documentation page.null
tooltipsNohideonclearNot an option that you'll need particularly often if at all. Setting this to true means that when you call the RGraph.clear() API function tooltips DO NOT get hidden.false
tooltipsFormattedPointWhen using formatted tooltip strings this is used as the point when using the %{value_formatted} option..
tooltipsFormattedThousandWhen using formatted tooltip strings this is used as the thousand separator when using the %{value_formatted} option.,
tooltipsFormattedDecimalsWhen using formatted tooltip strings this specifies the number of decimals when using the %{value_formatted} option.0
tooltipsFormattedUnitsPreWhen using formatted tooltip strings these units are prepended to the number when using the %{value_formatted} option.(an empty string)
tooltipsFormattedUnitsPostWhen using formatted tooltip strings these units are appended to the number when using the %{value_formatted} option.(an empty string)
tooltipsFormattedKeyColorsWhen using formatted tooltip strings you can give specific colors for the %{key} option to use.null
tooltipsFormattedKeyColorsShapeThis is the shape that's used in the tooltip key. It can be square or circlesquare
tooltipsFormattedKeyLabelsWhen using formatted tooltip strings these are the labels that are displayed.[] (an empty array)
tooltipsCssIf you want to specify some CSS that gets applied to all of the tooltips, but don't want to use the RGraph.tooltips.style object (which gets applied to all of the tooltips on the page for every chart) you can use this property to give some per-object CSS for the tooltips. These are CSS styles that get applied to all of the tooltips for the specific object only. It should look like this:
tooltipsCss: {
    fontFamily: 'Verdana',
    fontSize: '20pt',
    backgroundColor: 'black',
    color: 'white'
}
null
tooltipsCssClassThis is the name of the CSS class the chart uses.RGraph_tooltip
tooltipsOffsetxThis property allows you to shift the tooltips left or right.0
tooltipsOffsetyThis property allows you to shift the tooltips up or down.0
annotatableWhether annotations are enabled for the chart (ie you can draw on the chart interactively.false
annotatableColorIf you do not allow the use of the palette, then this will be the only color allowed for annotations.black
annotatableLinewidthThis is the linewidth of the annotations.1
adjustableBy setting this you can allow your chart to be adjustable. There's a documentation page about adjusting the Horizontal Bar chart here.false
adjustableOnlyThis should be an array of values that determine whether a Bar is adjustable or not. A truthy value for when it is, a falsey value for when it's not.null
contextmenu
An array of context menu items. You cannot have context menus AND tooltips, only one or the other. More information about context menus is here.
Default: [] (An empty array)

tooltips
An array of tooltips for the chart.
Default: An empty array

tooltipsEvent
This is the event that triggers the tooltips. It can be click or mousemove.
Default: onclick

tooltipsEffect
The effect used for showing tooltips. Can be either fade or none.
Default: fade

tooltipsOverride
If you wish to handle showing tooltips yourself, this should be a function object which does just that. There's more information on the tooltips documentation page.
Default: null

tooltipsNohideonclear
Not an option that you'll need particularly often if at all. Setting this to true means that when you call the RGraph.clear() API function tooltips DO NOT get hidden.
Default: false

tooltipsFormattedPoint
When using formatted tooltip strings this is used as the point when using the %{value_formatted} option.
Default: .

tooltipsFormattedThousand
When using formatted tooltip strings this is used as the thousand separator when using the %{value_formatted} option.
Default: ,

tooltipsFormattedDecimals
When using formatted tooltip strings this specifies the number of decimals when using the %{value_formatted} option.
Default: 0

tooltipsFormattedUnitsPre
When using formatted tooltip strings these units are prepended to the number when using the %{value_formatted} option.
Default: (an empty string)

tooltipsFormattedUnitsPost
When using formatted tooltip strings these units are appended to the number when using the %{value_formatted} option.
Default: (an empty string)

tooltipsFormattedKeyColors
When using formatted tooltip strings you can give specific colors for the %{key} option to use.
Default: null

tooltipsFormattedKeyColorsShape
This is the shape that's used in the tooltip key. It can be square or circle
Default: square

tooltipsFormattedKeyLabels
When using formatted tooltip strings these are the labels that are displayed.
Default: [] (an empty array)

tooltipsCss
If you want to specify some CSS that gets applied to all of the tooltips, but don't want to use the RGraph.tooltips.style object (which gets applied to all of the tooltips on the page for every chart) you can use this property to give some per-object CSS for the tooltips. These are CSS styles that get applied to all of the tooltips for the specific object only. It should look like this:
tooltipsCss: {
    fontFamily: 'Verdana',
    fontSize: '20pt',
    backgroundColor: 'black',
    color: 'white'
}

Default: null

tooltipsCssClass
This is the name of the CSS class the chart uses.
Default: RGraph_tooltip

tooltipsOffsetx
This property allows you to shift the tooltips left or right.
Default: 0

tooltipsOffsety
This property allows you to shift the tooltips up or down.
Default: 0

annotatable
Whether annotations are enabled for the chart (ie you can draw on the chart interactively.
Default: false

annotatableColor
If you do not allow the use of the palette, then this will be the only color allowed for annotations.
Default: black

annotatableLinewidth
This is the linewidth of the annotations.
Default: 1

adjustable
By setting this you can allow your chart to be adjustable. There's a documentation page about adjusting the Horizontal Bar chart here.
Default: false

adjustableOnly
This should be an array of values that determine whether a Bar is adjustable or not. A truthy value for when it is, a falsey value for when it's not.
Default: null

Miscellaneous properties

PropertyDescriptionDefault
groupingHow the bars are grouped, and it should be one of: grouped or stacked.grouped
highlightStrokeIf you use tooltips, this controls the color of the highlight stroke.black
highlightFillIf you use tooltips, this controls the color of the highlight fill.rgba(255,255,255,0.5)
cleartoThis is used in animations and effects as the default color to use when the canvas.null
highlightStyleBy default this is null but you can set it to a function if you wish so that function is called to do the chart highlighting. It's passed the shape object as an argument. As of version 5.23 you can also set this to invert as well. If you do this on a dark background you may find that you need to change the highlightFill color setting as well.null
variantThis stipulates whether you want a regular Horizontal Bar chart or a 3D chart. Possible values are:
  • hbar
  • 3d
hbar
variantThreedOffsetxThis determines the size of the offset in the X direction.10
variantThreedOffsetyThis determines the size of the offset in the Y direction.5
variantThreedXaxisThis allows you to turn on/off the 3D X axis.true
variantThreedYaxisThis allows you to turn on/off the 3D Y axis.true
grouping
How the bars are grouped, and it should be one of: grouped or stacked.
Default: grouped

highlightStroke
If you use tooltips, this controls the color of the highlight stroke.
Default: black

highlightFill
If you use tooltips, this controls the color of the highlight fill.
Default: rgba(255,255,255,0.5)

clearto
This is used in animations and effects as the default color to use when the canvas.
Default: null

highlightStyle
By default this is null but you can set it to a function if you wish so that function is called to do the chart highlighting. It's passed the shape object as an argument. As of version 5.23 you can also set this to invert as well. If you do this on a dark background you may find that you need to change the highlightFill color setting as well.
Default: null

variant
This stipulates whether you want a regular Horizontal Bar chart or a 3D chart. Possible values are:
Default: hbar

variantThreedOffsetx
This determines the size of the offset in the X direction.
Default: 10

variantThreedOffsety
This determines the size of the offset in the Y direction.
Default: 5

variantThreedXaxis
This allows you to turn on/off the 3D X axis.
Default: true

variantThreedYaxis
This allows you to turn on/off the 3D Y axis.
Default: true

Methods

obj.get(name)
An accessor that you can use to retrieve the values of properties.


obj.set(name, value)
An accessor that you can use to set the values of properties.


obj.getShape(event)
This method makes it easy to get hold of which bar or segment has been clicked on or hovered over. It returns an object which has the following indexes available:

object The chart object
x The X coordinate
y The Y coordinate
width The width of the bar
height The height of the bar
dataset The zero-indexed "group". In a regular Bar chart this is the index of the bar. In a stacked or grouped chart however this is the index of the group (or stack).
index The zero-indexed numerical index of the bar. In a stacked or grouped chart this is the index in a particular group. In a regular Bar chart this is always zero. Note that in a stacked chart the counting starts from the top-most segment (which is zero).
sequentialIndex The zero-indexed sequential index of the bar. For example in a grouped chart where there's three groups of three - this goes from 0 up to 8.
tooltip If a tooltip is associated with this bar or segment this will be it.id: strings are expanded for you (where the tooltip text is retrieved from the HTML tag with the matching ID).
<script>
    obj.canvas.onclick = function (e)
    {
        RGraph.redraw();
    
        var canvas  = e.target,
            obj     = canvas.__object__,
            shape   = obj.getShape(e);

        if (shape) {
            var x      = shape.x,
                y      = shape.y,
                width  = shape.width,
                height = shape.height;
            
            obj.path(
                'b r % % % % s black f red',
                x, y, width, height
            );
        }
    }
</script>


obj.getShapeByY(event[, object])

This method is similar to the getShape() method described above but when comparing the mouse position to the bar coordinates this method only takes into account the mouse Y position. This method is used when the Horizontal Bar chart is made to be adjustable.

The second argument is optional and allows you to specify the (RGraph) object to be used in the checks.


obj.getValue(mixed)

This method can be used to get the value at a particular point or at the mouse coordinates, based on the scale that is in use. Not simply the coordinates of the mouse. The argument can either be an event object (for use in event listener functions) OR a two element array consisting of the X and Y coordinates (ie when you're not necessarily in an event listener). It returns null if the mouse or coordinates are in the margin areas. An example:

myChart.canvas.onclick = function (e)
{
    var obj   = e.target.__object__;
    var value = obj.getValue(e);
    
    // ...
}

obj.getXCoord(value)

This method can be used to get an appropriate X coordinate for a value when you're doing custom drawing on the chart. It returns null if the value is out of range.


obj.on(event, function)

This method can be used to set an event listener on an object. It operates in a similar way to the jQuery on() function. The first argument is the event that you wish to attach to and the second is the handler function. For example:

obj.on('draw', function (obj)
{
    // Put your event code here
});

The function is useful if you use method chaining when creating your charts:

obj = new RGraph.HBar({
    id: 'cvs',
    data: [5,8,6,4,3,5],
    options: {
        marginLeft: 55,
        marginInner: 5,
        yaxisLabels: ['Hoolio','Jill','Pete','Kevin','Lucy','John']
    }
}).on('mousemove', function (e, shape)
{
    // Put your mousemove event code here

}).on('click', function (e, shape)
{
    // Put your click event code here
})
.draw()

obj.exec(function)

The exec function is documented here.

Custom RGraph events that are available

Custom RGraph events are events that RGraph fires when certain actions occur. There is a more comprehensive list of these events here . Here's some example code that show you how to add these events to your chart.

There's more documentation about events available here: Summary of events documentation

<script>
    hbar = new RGraph.HBar({
        id: 'cvs',
        data: [4,6,2,4,8,5,8],
        options: {
        }
    }).draw().on('click', function (e, shape)
    {
        // Add your click event listener code here

    }).on('mousemove', function (e, shape)
    {
        // Add your mousemove event listener code here

    }).on('mouseover', function (e, shape)
    {
        // Add your mouseover event listener code here

    }).on('mouseout', function (obj)
    {
        // Add your mouseout event listener code here
    });
</script>

Note about the data_arr array

Sometimes you may wish to view your data as one big array, instead of one array per dataset. In this case the obj.data_arr is available. This is one long array containing all of the individual data points.

Animation Effects

These effects are available and can be used instead of the draw() function. There are also generic effects available which you can see here: Generic effects and transitions
<script>
    /**
    * Optional callback function that's called when the effect is complete
    */
    function myCallback (obj)
    {
        // ...
    }

    obj = new RGraph.HBar({
        id: 'cvs',
        data: [4,8,6,3,5,2,4],
        options: {
            marginLeft: 35,
            marginInner: 5
        }
    }).grow({frames: 60}, myCallback)
</script>