The drawing API X axis object

Share RGraph:   Share or Like RGraph on Facebook!
[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>
   var bar = new RGraph.Bar({
        id: 'cvs',
        data: [4,8,6,5,6,9,9,4],
        options: {
            noaxes: true,
            textAccessible: true,
            textSize: 14,
            scaleZerostart: true,
            gutterBottom: 45,
            colors: ['gradient(white:red)'],
            shadow: false,
            backgroundGridVlines: false,
            backgroundGridBorder: false
        }
    }).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',
            textAccessible: true,
            textSize: 14
        }
    }).draw();
</script>

Properties

Layout style:     
  

Colors

PropertyDescriptionDefault
colorsAn array of colors. Event though it's an array only the first color is used.['black']

Titles

PropertyDescriptionDefault
titleThe title for the axis.An empty string
titleColorThe color of the title. If not specified then it's the same as the colors option.null

Margins

PropertyDescriptionDefault
gutterLeftThe left gutter of the axis. This can be the same or different to the chart.25
gutterRightThe rightgutter of the axis. This can be the same or different to the chart.25
hmarginThe horizontal margin of the axis. Useful for matching up labels/points of the Line chart.0

Labels and text

PropertyDescriptionDefault
labelsInstead of a scale you can use this to specify labels for the X axis.null
labelsPositionThis 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.section
numlabelsWhen showing a scale this determines how many labels are shown by default.5
textColorThe color of the text. If not specified then it's the same as the colors option.null
textFontThe font used when rendering the text.Arial
textSizeThe size used when rendering text10

Axis properties

PropertyDescriptionDefault
numticksThe number of tickmarks shown on the axis. You may need to +/- 1 to get alignment with grids.null
alignThe alignment of the tickmarks and labels. This can be top or bottom.bottom
yaxisposThis can facilitate when you have a Y axis in the center (eg the Horizontal Bar chart).left
noendtickLeftThis option can be used to prevent the left end tickmark from being drawn.false
noendtickRightThis option can be used to prevent the right end tickmark from being drawn.false
noxaxisThis option can be specified if you don't want an axis drawn (the labels are still drawn).false
linewidthThe linewidth used to draw the axis.1
xaxisposUusually bottom, though you can set this to center and the tickmarks will start above the axis and end below the axis.bottom

Scale

PropertyDescriptionDefault
scaleFormatterThis 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)
null
scaleDecimalsThe number of decimals shown.0
scaleInvertWhether the scale is inverted (ie minimum value at the top)false
scaleZerostartThis determines whether zero is shown.true
scaleVisibleThis determines whether the scale is displayed.true
unitsPreThe units for the scale. This is prepended to the number.An empty string
unitsPostThe units for the scale. This is appended to the number.An empty string
maxThe maximum value of the scale.null
minThe minimum value of the scale.0

Interactive features

PropertyDescriptionDefault
tooltipsThis can be array of tooltips (only the first element is used) that are shown when the axis is clicked on.null
tooltipsEventThis is the event that triggers the tooltips. It can be either onclick or onmousemove.onclick
tooltipsEffectThe effect used for showing tooltips. Can be either fade or none.fade
tooltipsCssClassThis is the name of the CSS class the chart uses.RGraph_tooltip
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 pagenull
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 tooltip DO NOT get hidden.false

Events

PropertyDescriptionDefault
eventsClickIf you want to add your own onclick function you can do so by assigning it to this property. See here for details.null
eventsMousemoveIf you want to add your own onmousemove function you can do so by assigning it to this property. See here for details.null

Miscellaneous

PropertyDescriptionDefault
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. Its passed the shape object as an argument.null
© Copyright Richard Heyes 2008-2017