The drawing API X axis object


[No canvas support]

The X axis object allows you to have extra X axes in your chart. Formerly this was an independent function but it's now been converted to a drawing API object. This means that it's easier to use and has added interactivity options - such as mousemove and click events and tooltips.

Usage example

<script>
    $(document).ready(function ()
    {
       var bar = new RGraph.Bar({
            id: 'cvs',
            data: [4,8,6,5,6,9,9,4],
            options: {
                noaxes: true,
                gutterBbottom: 45
            }
        }).draw();
        
        var xaxis = new RGraph.Drawing.XAxis({
            id: 'cvs',
            y: bar.canvas.height - bar.gutterBottom,
            options: {
                tooltips: ['The X axis represents each<br />person teaching at the college.'],
                labels: ['Rich','Alex','Johnny','Kev','Pete','Luis','John','Barry'],
                colors: ['#666'],
                title: 'The X axis'
            }
        }).draw();
    })
</script>

Properties

 

Colors

colors
An array of colors. Event though it's an array only the first color is used.
Default: ['black']

 

Titles

title
The title for the axis.
Default: An empty string

titleColor
The color of the title. If not specified then it's the same as the colors option.
Default: null

 

Margins

gutterLeft
The left gutter of the axis. This can be the same or different to the chart.
Default: 25

gutterRight
The rightgutter of the axis. This can be the same or different to the chart.
Default: 25

hmargin
The horizontal margin of the axis. Useful for matching up labels/points of the Line chart.
Default: 0

 

Labels and text

labels
Instead of a scale you can use this to specify labels for the X axis.
Default: null

labelsPosition
This cand be edge or section and detemines how the labels are aligned. For an illustration compare the labels of the Bar chart vs the labels of the Line chart.
Default: section

numlabels
When showing a scale this determines how many labels are shown by default.
Default: 5

textColor
The color of the text. If not specified then it's the same as the colors option.
Default: null

textFont
The font used when rendering the text.
Default: Arial

textSize
The size used when rendering text
Default: 10

 

Axis properties

numticks
The number of tickmarks shown on the axis. You may need to +/- 1 to get alignment with grids.
Default: null

align
The alignment of the tickmarks and labels. This can be top or bottom.
Default: bottom

yaxispos
This can facilitate when you have a Y axis in the center (eg the Horizontal Bar chart).
Default: left

noendtickLeft
This option can be used to prevent the left end tickmark from being drawn.
Default: false

noendtickRight
This option can be used to prevent the right end tickmark from being drawn.
Default: false

noxaxis
This option can be specified if you don't want an axis drawn (the labels are still drawn).
Default: false

linewidth
The linewidth used to draw the axis.
Default: 1

xaxispos
Uusually bottom, though you can set this to center and the tickmarks will start above the axis and end below the axis.
Default: bottom

 

Scale

scaleFormatter
This should be a function that returns the correctly formatted number. For example:
function myFormatter (obj, number)
{
    // Return the formatted number
    return number;
}

xaxis.set('scale.formatter', myFormatter)

Default: null

scaleDecimals
The number of decimals shown.
Default: 0

scaleInvert
Whether the scale is inverted (ie minimum value at the top)
Default: false

scaleZerostart
This determines whether zero is shown.
Default: true

scaleVisible
This determines whether the scale is displayed.
Default: true

unitsPre
The units for the scale. This is prepended to the number.
Default: An empty string

unitsPost
The units for the scale. This is appended to the number.
Default: An empty string

max
The maximum value of the scale.
Default: null

min
The minimum value of the scale.
Default: 0

 

Interactive features

tooltips
This can be array of tooltips (only the first element is used) that are shown when the axis is clicked on.
Default: null

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

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

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

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

 

Events

eventsClick
If you want to add your own onclick function you can do so by assigning it to this property. See here for details.
Default: null

eventsMousemove
If you want to add your own onmousemove function you can do so by assigning it to this property. See here for details.
Default: null