Line chart API reference

Documentation about the Line chart including information about all of the options that are available to you. The Line chart is a commonly used type of chart and can show one or more datasets. It's one of the more commonly used types of chart and as such there are a lot of Line chart demos.

Note: With the Line chart, there isn't an option to have a scale on the X axis. For this you'll need a Scatter chart with the line option set to true. You can either use labels across the X axis or an X scale. Or as of February 2013 you can also use the X axis drawing object.

Example

<script>
    data = [
        [8,7,6,4,9,5,6,7,9],
        [4,3,5,8,6,4,2,4,9],
        [8,4,9,5,3,5,1,2,5]
    ];

    new RGraph.Line({
        id: 'cvs',
        data: data,
        options: {
            backgroundGridColor: 'rgba(238,238,238,1)',
            colors: ['black'],
            linewidth: 3,
            filled: true,
            filledColors: ['red','blue','#0f0'],
            spline: true,
            shadow: false,
            tickmarksStyle: null,
            xaxisLabels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
            axes: false,
            marginLeft: 40
        }
    }).trace();
</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 is shown above.

Background properties

PropertyDescriptionDefault
backgroundBarsCountThe number of background bars.5
backgroundBarsColor1The colour of the background bars (1 of 2).rgba(0,0,0,0)
backgroundBarsColor2The colour of the background bars (2 of 2).rgba(0,0,0,0)
backgroundGridWhether to show the background grid or not.true
backgroundGridColorThe colour of the background grid.#eee
backgroundHbarsAn array of information stipulating horizontal coloured bars. You can use these to indicate limits. Eg: myLine.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.null
backgroundGridLinewidthThe width of the background grid.1
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
backgroundGridAutofitInstead of specifying a pixel width/height for the background grid, you can use autofit and specify how many horizontal and vertical lines you want.true
backgroundGridHlinesCountWhen using autofit this allows you to specify how many horizontal grid lines you want.5
backgroundGridVlinesCountWhen using autofit this allows you to specify how many vertical grid lines you want.20
backgroundGridAlignIf you want to have your grid lines line up with the labels (both X and Y axes), you can set this to true and RGraph will attempt to make the grid lines line up. If you have a hmargin set then the alignment will be thrown out.true
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
backgroundImageIf you want to specify a background image to use on your chart, specify it with this property. If you use effects with a background image on your chart it may make the effect flicker. Using a background image with the ondraw event may mean that the event fires twice. There is a property that you can check though that is set when the image has loaded: obj.__rgraph_background_image_loaded__ Simply check this flag in your ondraw event. If it's true then the background image has loaded.null
backgroundImageStretchBy default your background image is stretched (if necessary) to cover the whole chart area (margins not included). If this is not what you want then set this property to false.true
backgroundImageXThe X position of the image. The coordinates are the top left corner of the image.null
backgroundImageYThe Y position of the image. The coordinates are the top left corner of the image.null
backgroundImageWThe width of the image. If you have a large canvas with many charts - you may need to specify this.null
backgroundImageHThe height of the image. If you have a large canvas with many charts - you may need to specify this.null
backgroundImageAlignInstead of specifying the coordinates of the image, you can instead simply align it top, bottom, left or right. Examples are:
  • top left
  • bottom right
  • bottom
  • right
null
backgroundImageAlphaThe alpha value (the opacity) of the image.1
backdropWhen enabled this specifies that the line(s) will have a backdrop effect. You can control the transparency with the other backdrop settings).false
backdropSizeThis controls the size/extent of the backdrop effect.30
backdropAlphaThis controls how much transparency the backdrop effect has. It can go from 0 - 1.0.2

General axis properties

PropertyDescriptionDefault
axesWhether the axes are drawn.true
axesColorThe colour of the axes.black
axesLinewidthThe linewidth of the axes.1

X axis properties

PropertyDescriptionDefault
xaxisLabelsInsideThis controls whether the X labels are drawn inside the X axis or not. By using this you can significantly reduce the size of the margins needed.false
xaxisLabelsInsideBorderWhether the inside X axis labels have a border or not.false
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
xaxisLabelsAn array of the X labels for the chart.An empty array
xaxisLabelsFontThe font used to render the X axis labels.null (defaults to textFont)
xaxisLabelsSizeThe size of the X axis labels.null (defaults to textSize)
xaxisLabelsColorThe colour of the X axis labels.null (defaults to textColor)
xaxisLabelsBoldWhether the X axis labels are bold or not.null (defaults to textBold)
xaxisLabelsItalicWhether the X axis labels are italic or not.null (defaults to textItalic)
xaxisLabelsAngleThe angle of the X axis labels. This can be from 90 to -90 degrees.0 (Horizontal)
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 (defaults to the textSize setting)
xaxisTitleFontThis allows you to specify a font for the X axis title.null (defaults to the textFont setting)
xaxisTitleBoldThis controls whether the X axis title is bold or not.true
xaxisTitleItalicThis controls whether the X axis title is italic or not.null (defaults to the textItalic setting)
xaxisTitleColorThis controls the colour of the X axis title.null (defaults to the textColor setting)
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
xaxisTitlePosThis is multiplied with the margin to give the position of the X axis title.0.25
xaxisTickmarksCountThe number of X tick marks.null (linked to number of data points)
xaxisPositionThe position of the X axis. It can be bottom, center or top.bottom
xaxisTickmarksLastWhen you're combining the Bar and Line charts, you may want to use this property to stop the end X tick from being drawn.true

Y axis properties

PropertyDescriptionDefault
yaxisLabelsCan be true or false and determines whether the chart has Y axis labels.true
yaxisLabelsCountA value that controls how many Y labels there are. Formerly this could be 1/3/5/10 but now it can be any number.5
yaxisLabelsFontThe font used for the Y axis text.null
yaxisLabelsSizeThe size used for the Y axis text.null
yaxisLabelsColorThe colour used for the Y axis text.null
yaxisLabelsBoldWhether the Y axis text is bold or not.null
yaxisLabelsItalicWhether the Y axis text is italic or not.null
yaxisLabelsInsideWhether the Y axis labels are drawn inside the axis.false
yaxisLabelsSpecificYou can use this option to give your own Y labels (eg ['Low', 'Medium', 'High']. Note: Since March 2013 you may now need to add an extra (optionally) empty element to the array of labels to achieve your desired result.null
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
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
yaxisTitleItalicThis controls whether the Y axis title is italic or not.null
yaxisTitleColorThis controls what colour the Y axis is.null
yaxisTitlePosThis is multiplied with the margin to give the position of the Y axis title.0.25
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
yaxisScaleUnitsPostThe units (if any) that the Y axis is measured in (gets appended to the number).none
yaxisScaleUnitsPreThe units (if any) that the Y axis is measured in (gets prepended to the number).none
yaxisScaleDecimalsDetermines the precision of the numbers used as the scale.0
yaxisScalePointThe character used as the decimal point..
yaxisScaleThousandThe character used as the thousand separator.,
yaxisScaleRoundWhether to round the maximum scale value up or not. This will produce slightly better scales in some instances.null
yaxisScaleInvertReverses the Y axis scale so that the minimum value is at the top, instead of the bottom.false
yaxisScaleZerostartWhether the scale starts at zero or not.true
yaxisScaleMinThe optional minimum Y scale value. If not specified then it will be zero.null
yaxisScaleMaxThe optional maximum Y scale value. If not specified then it will be calculated.null (It's calculated)
yaxisScaleFormatterTo allow thoroughly custom formats of numbers in the scale, you can use this option to specify a function that is used by RGraph to format numbers. This function should handle ALL of the formatting. Eg:

function myFormatter(obj, num)
{
    return num + 'F'; // An example of formatting
}
myGraph.set('scale.formatter', myFormatter);
null
yaxisTickmarksCountThe number of Y tick marks.10
yaxisPositionSpecifies the Y axis position. Can be left or right.left
yaxisTickmarksLastWhen you're combining the Bar and Line charts, you may want to use this property to stop the end Y tick from being drawn.true
outofboundsNormally, out-of-bounds values are not drawn. By setting this to true you can change this behaviour.false
outofboundsClipIf you've enabled the outofbounds option but you're not interested in seeing the bits which fall outside of the chart area (eg in the margins) then you can enable this option. There's a demo of the outofboundsClip option in the download archive (examples/line-overflow-clipped.html).false

Other label properties

PropertyDescriptionDefault
labelsAboveWhether the values are shown in labels drawn above the line.false
labelsAboveBoldWhether the labelsAbove labels are bold or not.null (defaults to the textBold setting)
labelsAboveItalicWhether the labelsAbove labels are italic or not.null (defaults to the textItalic setting)
labelsAboveSizeThe size of the labels which are drawn above the line.8
labelsAboveColorThe text colour of the labels.Same as the textColor setting
labelsAboveFontThe font used to render the labels.Same as textFont
labelsAboveDecimalsThe number of decimals to fit the numbers to. If left unset decimals may still be shown (depending on your data) - but some numbers may have lots of decimals, some not so many and some none at all. It all depends on your data.null
labelsAbovePointThe decimal point character for the labels above labels..
labelsAboveThousandThe thousand separator character for the labels above labels.,
labelsAboveBackgroundThe background colour of the labels.rgba(255,255,255,0.7)
labelsAboveBorderWhether the labels have a border or not.false
labelsAboveOffsetyThe Y offset of the label from the point on the line.5
labelsAboveUnitsPreThe units that appear BEFORE the label.none
labelsAboveUnitsPostThe units that appear AFTER the label.none
labelsAboveSpecificThis can be an array of (text) labels that you want to appear above the line instead of the values.null
labelsIngraphAn array of labels for the chart which are drawn "inside" the chart. If you have 5 data points then this should have a corresponding number of elements, though there is a shorthand available.null
labelsIngraphFontThe font that the ingraph labels are rendered in.null
labelsIngraphSizeThe size of the ingraph labels.null
labelsIngraphColorThe colour of the ingraph labels.null
labelsIngraphBoldWhether the ingraph labels are bold or not.null
labelsIngraphItalicWhether the ingraph labels are italic or not.null
textSizeThe size of the text (in points).12
textFontThe font used to render the text.Arial
textColorThe colour of the labels.black
textBoldThe colour of the labels.black
textItalicThe colour of the labels.black
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

Margin properties

PropertyDescriptionDefault
marginLeftThe left margin of the chart, (the margin is where the labels and title are)).25
marginRightThe right margin of the chart, (the margin is where the labels and title are).25
marginTopThe top margin of the chart, (the margin is where the labels and title are).25
marginBottomThe bottom margin of the chart, (the margin is where the labels and title are).25
hmarginThe size of the horizontal margin. This is on the inside of the axes.0

Colour properties

PropertyDescriptionDefault
colorsAn array of line colours.['#f00', '#0f0', '', '#00f', '#f0f', '#ff0', '#0ff']
colorsAlternateSet this to true if you want your line colour(s) to be alternated.false
filledWhether the area under the line is filled or not. This looks best when there is no horizontal margin.

Note: When showing multiple lines the values are additive by default. This means that if you have two lines they will be "stacked" on top of each other. If this is not the desired behaviour then you can set the option below to false.
false
filledColorsA single colour or an array of colours that filled line charts will use.

Important: This used to be a string, and still can be, but can now also be an array.
null
filledAccumulativeWhen showing multiple filled lines the values are by default accumulative (ie added to each other). If this is not the desired behaviour, then you can set this property to false to have them drawn "non-accumulatively".

Note: If you use fully opaque colours in conjunction with this option set to false it's feasible that you might not see one or more of the lines, or parts of the line. If you want to see all of the lines you should leave this option set to its default true setting. You can see an example of this setting here.

true
filledRangeThis is useful for indicating a range. Exactly two datasets are required, with the space between them filled. This is useful for indicating a range.false
filledRangeThresholdWhen drawing a filled range chart you set a threshold in the case where you want the range to be one colour above the threshold and another below.null
filledRangeThresholdColorsThis is a two element array that defines the colours when using a dual colour range chart. There's an example of the dual colour range chart in the download archive (examples/line-dual-color-range.html).['red', 'green']

Shadow properties

PropertyDescriptionDefault
shadowWhether a drop shadow is applied.false
shadowColorThe colour of the shadow.rgba(0,0,0,0.5)
shadowOffsetxThe X offset of the shadow.2
shadowOffsetyThe Y offset of the shadow.2
shadowBlurThe severity of the shadow blurring effect.3

Interactive features properties

PropertyDescriptionDefault
tooltipsA numerically indexed array of tooltips that are shown when a bar is clicked. These can contain HTML.An empty array
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 page.null
tooltipsHighlightSet this to false if you don't want your charts to be highlighted.true
tooltipsHotspotXonlySet this to true if you want the tooltips to be triggered by the mouse X position only.false
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
tooltipsHotspotSizeThe size of the hotspot area for tooltips.5
crosshairsIf true, you will get a crosshair centering on the current mouse position.false
crosshairsLinewidthThis controls the linewidth of the crosshairs.1
crosshairsColorThe colour of the crosshairs.#333
crosshairsHlineThis determines whether the horizontal crosshair is shown.true
crosshairsVlineThis determines whether the vertical crosshair is shown.true
contextmenuAn array of context menu items. More information about context menus is here.[] (An empty array)
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 colour allowed for annotations.black
annotatableLinewidthThis is the line width of the annotations.1
resizableDefaulting to false, this determines whether your chart will be resizable. Because of the numerous event handlers this has to install code on, This feature is unlikely to work with other dynamic features (the context menu is fine however).false
resizableHandleBackgroundWith this you can specify the background colour for the resize handle. If you're adjusting the position of the handle then you may need this to make the handle stand out more.null
resizableMinwidthThis allows you to set a minimum width that the chart can be resized to.null
resizableMinheightThis allows you to set a minimum height that the chart can be resized to.null
resizableMaxwidthThis allows you to set a maximum width that the chart can be resized to.null
resizableMaxheightThis allows you to set a maximum height that the chart can be resized to.null
adjustableDefaulting to false, this determines whether your bar chart will be adjustable.false
adjustableOnlyThis should be an array of values that determine whether a point is adjustable or not. A truthy value for when it is, a falsey value for when it's not.null

Title properties

PropertyDescriptionDefault
titleThe title of the chart.none
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.true
titleItalicWhether the title is italic or not.false
titleColorThe colour of the title.black
titleBackgroundThe background colour (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

Key properties

key properties are documented on the key documentation page.

Event properties

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
eventsMouseoverIf you want to add your own onmouseover function you can do so by assigning it to this property. See here for details.null
eventsMouseoutIf you want to add your own onmouseout function you can do so by assigning it to this property. See here for details.null

Miscellaneous properties

PropertyDescriptionDefault
tickmarksStyleWhat kind of tick marks to use on the chart. This can be:
  • circle
  • filledcircle
  • endcircle
  • filledendcircle
  • square
  • endsquare
  • filledsquare
  • filledendsquare
  • tick
  • halftick
  • endtick
  • cross
  • dot
  • borderedcircle (same as dot)
  • arrow
  • filledarrow
  • triangle
  • filledtriangle

Note that "arrow" and "filledarrow" look better with a thinner (1 or 2) linewidth setting.

Also note that as well as a string, this can be an array of different tick mark styles.

As of August 2014 this can be a location/URL of an image file to use as the tick marks or a data: URL. See below for details.

null
tickmarkSizeThe size of the tick marks.3
tickmarksStyleDotStrokeThis is the colour of the filled part of the dot/borderedcircle style tick marks.null (defaults to the line colour)
tickmarksStyleDotFillThis is the colour of the stroked part of the dot/borderedcircle style tick marks.null (defaults to the line colour)
tickmarksStyleDotLinewidthThis is the width of the line used when drawing the tick marks.0
tickmarksStyleImageHalignThis can be left, right or center and determines the horizontal alignment of the tick mark.center
tickmarksStyleImageValignThis can be top, bottom or center and determines the vertical alignment of the tick mark.center
tickmarksStyleImageOffsetxAfter the alignment has been applied, this is added to the X coordinate of the tick mark.0
tickmarksStyleImageOffsetyAfter the alignment has been applied, this is added to the Y coordinate of the tick mark.0
steppedDraws the line as stepped. Useful for showing stock performance for example.false
linewidthThe width of the line (ie the actual line on the chart). Note: If your line is stepped and filled, and you don't want a trailing line indicating the last value, you can set this to zero.1
animationUnfoldXThis is used by the Unfold Line chart animation and dictates whether the X value is unfolded.false
animationUnfoldYThis is used by the Unfold Line chart animation and dictates whether the Y value is unfolded.true
animationUnfoldInitialThis property can be used to set the initial factor for the Unfold animation. Setting this to a value less than one will cause the line to expand outwards, whilst a value greater than one will cause the line to contract towards the correct values.2
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.

Updated: As of June 2016 you can also set this to halo to get a new style of highlighting. This style of highlighting doesn't work with the tooltipsHotspotXonly option.

null
highlightStrokeIf you use tooltips, this controls the colour of the highlight stroke.black
highlightFillIf you use tooltips, this controls the colour of the highlight fill.rgba(255,255,255,0.5)
splineThis option causes the line to be drawn as a spline - ie curvy. Not all options will work with splines - however the introduction of real splines over the previous curvy option is a significant improvement. The line chart on the front page of the website shows this option. Null values will not work with splines.false
cleartoThis is used in animations and effects as the default colour to use when the canvas.null
combinedEffectSet this to the name of an effect (eg grow ) and the CombinedChart object will use that effect to draw the chart instead of the regular draw() function.null
combinedEffectOptionsThis should be a STRING that contains a JavaScript object of options for the effect function like this:
combinedchartEffectOptions: '{frames: 300}'
It has to be a string because of a quirk of the option parsing system.
null
combinedEffectCallbackA function that runs when this objects effect has completed.null
dottedWhether the line (not the background grid) is dotted or not. This is a new addition in January 2017 and is thanks to a submission by Garaged.false
dashedWhether the line (not the background grid) is dashed or not. This is a new addition in January 2017 and is thanks to a submission by Garaged.false

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 easier to get hold of which point on the Line chart has been hovered over. It returns an array of:

The shape also includes textual indexes like this: shape['object'] And they are:

An example usage is:
<canvas id="cvs" width="600" height="300">[No canvas support]</canvas>

<script src="RGraph.common.core.js"></script>
<script src="RGraph.line.js"></script>

<script>
    var line = new RGraph.Line({
        id: 'cvs',
        data: [10,4,2,4,1],
        options: {
            hmargin: 10,
            tickmarksStyle: 'endcircle',
            xaxisLabels: ['Fred','John','Kev','Lou','Pete']
        }
    }).draw();
    
    
    line.canvas.onmousemove = function (e)
    {
        RGraph.fixEventObject(e);

        var ca  = e.target,
            co  = ca.getContext('2d'),
            obj = ca.__object__;
       
        // This is the method which simplifies getting coordinates
        var point = obj.getShape(e);
       
       
        if (point) {

            if (line.hidden(point.dataset)) {
                return;
            }
             
            ca.style.cursor = 'pointer';
             
            // Determine if this is the same tooltip as the one (if any) that's already being shown
            if (RGraph.Registry.get('chart.tooltip') && RGraph.Registry.get('chart.tooltip').__index__ == point[3]) {
                return;
            }

            // Redraw the chart
            RGraph.redraw();

            // Show the tooltip
             if (obj.get('xaxisLabels')[point[3]] !== undefined && obj.get('xaxisLabels')[point[3]] !== null) {


                // Show the tooltip
                 RGraph.tooltip(
                    obj,
                    obj.get('xaxisLabels')[point[3]].toString(),
                    e.pageX,
                    e.pageY,
                    point[3],
                    e
                );


                // Highlight the point
                co.strokeStyle = 'gray';
                co.fillStyle   = 'white';

                co.beginPath();
                    co.moveTo(point[1], point[2]);
                    co.arc(
                        point[1],
                        point[2],
                        2,
                        0,
                        6.26,
                        false
                    );
                co.stroke();
                co.fill();
            }
             
            return;
        }
         
        ca.style.cursor = 'default';
    }




    window.onclick = function ()
    {
        RGraph.redraw();
    }
</script>
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:

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

This method can be used to get an appropriate Y coordinate for a value when you're doing custom drawing on the chart. It returns the coordinate for the maximum or minimum value if the given number 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:

.on('draw', function (obj)
{
    // Put event code here
});
The exec option and method

The exec function is documented here.

obj.hide([index])

The hide function hides a line by setting the colour to rgba(0,0,0,0). Tooltips and other interactive features still work even though the line is not visible. You can give an integer (the index of the relevant line), an array of line indexes, or no argument at all in which case all of the lines on the chart are hidden

obj.show([index])

This function is the reverse of the above.

obj.hidden(index)

This function returns true or false as to whether the given line index is hidden or not.

Errorbars

Errorbars can allow you to show an upper and lower range for a particular point like the example page (examples/line-errorbars.html) here shows. You can specify errorbars like this:

var line = new RGraph.Line({
    id: 'cvs',
    data: [12,18,10,8,5,4,3,2,14,5,6,9],
    options: {
        yaxisScaleMin: 5,
        errorbars: [1, [1,5],[5,1,'red',10],3,3,3,3,3,3,3,3,3,3],
        //errorbarsLinewidth: 10,
        //errorbarsColor: 'red',
        //errorbarsCapped: false,
        //errorbarsCappedWidth: 50,
        hmargin: 15,
        tickmarksStyle: 'circle',
        xaxis: false
    }
}).draw();

This would give you errorbars for each point and the elements of each errorbar array are (each one is optional - specify null if you want to give no value):

Combining the Line and Bar charts

You can combine the Bar and Line charts. Find out more here. In the same vein, you can have Y axes on both the left and right sides.

Alternative colours

Instead of a string stipulating the colour, each element of the colours array can be a two element array stipulating the up colour, and the down colour. To use alternating colours you must also stipulate the alternate property:

myLine.set('colors.alternate', true);
myLine.set('colors', ['red', ['blue', 'yellow'], 'green]);

Accumulative filled Line charts

The default behaviour of filled Line charts is to "stack" the lines on top of each other. This allows them all to be totally visible, no matter what (unless a line has a zero value of course). If this is not desired, then there is an option (filled.accumulative - true/false) to change this behaviour so that the lines are plotted "as-is". Keep in mind that if you set this option to false (ie the Lines are plotted as-is) it may be wiser to use semi-transparent colours or some parts of data sets (or even entire data sets) may be hidden by others. There's a comparison of the different modes here.

Custom tick marks

If none of the available tick mark styles are suitable, you can instead specify a function object that draws the tick mark, enabling you to make the tick mark yourself. For example:

<script>
    line.set('tickmarksStyle', myTick);

    /**
    * The function that is called once per tick mark, to draw it
    * 
    * @param object obj   The chart object
    * @param array  data  The entire line data
    * @param number value The individual point's value
    * @param number index The current index in the data array
    * @param number x     The X coordinate
    * @param number y     The Y coordinate
    * @param string color The colour of the line
    * @param number prevX The previous X coordinate
    * @param number prevY The previous Y coordinate
    */
    function myTick (obj, data, value, index, x, y, color, prevX, prevY)
    {
        // Draw your custom tick mark here
    }
</script>

As of August 2014 you can also specify an image to use as a tick mark. Various styles of URL are supported:

obj.set({tickmarksStyle: 'image:foo.png'});     // Starts with image: prefix
obj.set({tickmarksStyle: '/images/foo.png'});   // Starts with a /
obj.set({tickmarksStyle: '../images/foo.png'}); // Starts with ../
obj.set({tickmarksStyle: 'data: ...'});         // Starts with data: (for inline images)
obj.set({tickmarksStyle: 'images/foo.png'});    // Starts with images/

The coords2 array

An alternative method of indexing the chart coordinates is available in obj.coords2. With this array all of the first lines coordinates are available in obj.coords2[0], the second lines coordinates in obj.coords2[1] and so on.

The __index2__ property on tooltips

When showing tooltips, one property of the tooltip is .__index2__. This is the index that pertains to the individual dataset. In a function called from the ontooltip event you can access it like this:

function myFunc (obj)
{
    var idx = RGraph.Registry.get('chart.tooltip').__index2__;
}
RGraph.addCustomEventListener(obj, 'ontooltip', myFunc  );

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)
    {
        // ...
    }

    var obj = new RGraph.Gauge({
        id: 'cvs',
        min: 0,
        max: 100,
        value: 56,
        options: {
            marginLeft: 35,
            hmargin: 5
        }
    }).trace2({frames: 60}, myCallback)
    // .unfold({frames: 60}, myCallback)
    // .unfoldFromCenter({frames: 60}, myCallback)
    // .unfoldFromCenterTace({frames: 60}, myCallback)
    // .foldToCenter({frames: 60}, myCallback)
    // .trace2({frames: 60}, myCallback)
</script>