The RGraph Line chart documentation

Share RGraph:   Share or Like RGraph on Facebook!
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 now (February 2013 you could also use X axis drawing object.

 

Example

<script>
    // The data for the Line chart. Here we use multiple arrays for showing multiple lines.
    // Though it can just be an array of numbers to show just one line: var data = [4,8,6,5,8,7,5,6,6];
    var 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]
    ];

    var line = new RGraph.Line({
        id: 'cvs',
        data: data,
        options: {
            BackgroundBarcolor1: 'white',
            BackgroundBarcolor2: 'white',
            BackgroundGridColor: 'rgba(238,238,238,1)',
            colors: ['rgba(0,0,0,0)'],
            linewidth: 2,
            filled: true,
            fillstyle: ['red','blue','#0f0'],
            hmargin: 5,
            shadow: false,
            tickmarks: false,
            labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
            gutterLeft: 40
        }
    }).draw();
</script>

The example file is here.

 

Properties

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

Layout style:     
  

Background

PropertyDescriptionDefault
backgroundBarcolor1The color of the background bars (1 of 2).rgba(0,0,0,0)
backgroundBarcolor2The color of the background bars (2 of 2).rgba(0,0,0,0)
backgroundGridWhether to show the background grid or not.true
backgroundGridColorThe color of the background grid.#eee
backgroundHbarsAn array of information stipulating horizontal colored 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
backgroundGridWidthThe 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
backgroundGridAutofitNumhlinesWhen using autofit this allows you to specify how many horizontal grid lines you want.5
backgroundGridAutofitNumvlinesWhen using autofit this allows you to specify how many vertical grid lines you want. 20
backgroundGridAutofitAlignIf 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.false
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 (gutters 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
backgroundColorIf you want to have a single background color for your chart you can use this. It doesn't cover the gutters. If you want that then you can simply apply a CSS background color to the canvas tag.null

Labels and text

PropertyDescriptionDefault
labelsAboveWhether the values are shown in labels drawn above the line.false
labelsBoldWhether the labels are bold or notfalse
labelsOffsetxThis allows you finer grained control in the horizontal direction over the X label positioning if you need it.0
labelsOffsetyThis allows you finer grained control in the vertical direction over the X label positioning if you need it.0
labelsColorThe color of the labelsnull (same as textColor)
labelsAboveSizeThe size of the labels which are drawn above the line.8
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
labelsAboveColorThe text color of the labelsSame as the text.color setting
labelsAboveBackgroundThe background color of the labelswhite
labelsAboveFontThe font used to render the labelsSame as text.font
labelsAboveBorderWhether the labels have a border or nottrue
labelsAboveOffsetyThe Y offset of the label from the point on the line5
labelsAboveUnitsPreThe units that appear BEFORE the labelnone
labelsAboveUnitsPostThe units that appear AFTER the labelnone
labelsAboveSpecificThis can be an array of (text) labels that you want to appear above the line instead of the values.null
labelsAn array of the X labels for the chart.An empty array
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
ylabelsCan be true or false and determines whether the chart has Y axis labels.true
ylabelsCountA value (1, 3, 5 or 10) that controls how many Y labels there are. Formerly this could be 1/3/5/10 but now it can be any number.5
ylabelsInsideThis controls whether the Y labels are drawn inside the Y axis or not. If your labels are large, this may help.false
ylabelsInsideColorIf the Y labels are to be drawn inside the Y axis, this is used as the background color.rgba(255,255,255,0.5)
ylabelsSpecificYou 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
ylabelsOffsetxThis allows you finer grained control in the horizontal direction over the Y label positioning if you need it.0
ylabelsOffsetyThis allows you finer grained control in the vertical direction over the Y label positioning if you need it.0
xlabelsInsideThis controls whether the X labels are drawn inside the X axis or not. By using this you can significantly reduce the size of the gutters needed.false
xlabelsInsideColorIf the X labels are to be drawn inside the X axis, this is used as the background color.rgba(255,255,255,0.5)
textSizeThe size of the text (in points).10
textAngleThe angle of the horizontal text labels (at the bottom of the chart). This can be from 90 to -90 degrees.0 (Horizontal)
textFontThe font used to render the text.Arial
textColorThe color 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 gutters 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

Margins

PropertyDescriptionDefault
gutterLeftThe left gutter of the chart, (the gutter is where the labels and title are)).25
gutterRightThe right gutter of the chart, (the gutter is where the labels and title are).25
gutterTopThe top gutter of the chart, (the gutter is where the labels and title are).25
gutterBottomThe bottom gutter of the chart, (the gutter is where the labels and title are).25
hmarginThe size of the horizontal margin. This is on the inside of the axes.0

Colors

PropertyDescriptionDefault
colorsAn array of line colors.['#f00', '#0f0', '', '#00f', '#f0f', '#ff0', '#0ff']
colorsAlternateSet this to true if you want your line color(s) to be alternated. See notefalse
fillstyleA single color or an array of colors 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
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
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 colors 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 threshhold in the case where you want the range to be one color above the threshold and another below.null
filledRangeThresholdColorsThis is a two element array that defines the colors when using a dual color range chart. There's an example of the dual color range chart here.['red', 'green']

Shadow

PropertyDescriptionDefault
shadowWhether a drop shadow is applied.false
shadowColorThe color 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

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 pagenull
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 tooltip 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 color 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 on context menus is here.[] (An empty array)
annotatableWhether annotations are enabled for the chart (ie you can draw on the chart interactively.false
annotateColorIf you do not allow the use of the palette, then this will be the only colour allowed for annotations.black
annotateLinewidthThis 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
resizeHandleBackgroundWith this you can specify the background color 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 its not.null

Titles

PropertyDescriptionDefault
titleThe title of the none
titleFontThe font that the title is rendered in. If not specified the text.font setting is used (usually Arial)null
titleSizeThe size of the title. If not specified the size is usually 2pt bigger than the text.size setting.null
titleBoldWhather the title is bold or not.true
titleItalicWhether the title is italic or not.false
titleBackgroundThe background color (if any) for the title.null
titleXTo give the exact X coordinate for the title - use thisnull
titleYTo give the exact Y coordinate for the title - use thisnull
titleColorThe color of the title.black
titleXaxisThis allows to specify a title for the X axis.none
titleXaxisSizeThis allows you to specify a size for the X axis title.null
titleXaxisFontThis allows to specify a font for the X axis title.null
titleXaxisBoldThis controls whether the X axis title is bold or not.true
titleXaxisColorThis controls the color of the X axis title.black
titleXaxisXBy giving this you can specifically set the X position of the X axis titlenull
titleXaxisYBy giving this you can specifically set the Y position of the X axis titlenull
titleYaxisThis allows to specify a title for the Y axis.none
titleYaxisSizeThis allows you to specify a size for the Y axis title.null
titleYaxisFontThis allows to specify a font for the Y axis title.null
titleYaxisBoldThis controls whether the Y axis title is bold or not.true
titleYaxisColorThis controls what color the Y axis is.black
titleXaxisPosThis is multiplied with the gutter to give the position of the X axis title.0.25
titleYaxisPosThis is multiplied with the gutter to give the position of the Y axis title.0.25
titleYaxisXBy giving this you can specifically set the X position of the Y axis titlenull
titleYaxisYBy giving this you can specifically set the Y position of the Y axis titlenull

Key

The key properties are documented on the key documentation page.

Scale

PropertyDescriptionDefault
scaleFormatterTo 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
unitsPostThe units (if any) that the Y axis is measured in (gets appended to the number)none
unitsPreThe units (if any) that the Y axis is measured in (gets preppended to the number)none
scaleDecimalsDetermines the precision of the numbers used as the scale.0
scalePointThe character used as the decimal point..
scaleThousandThe character used as the thousand separator,
scaleRoundWhether to round the maximum scale value up or not. This will produce slightly better scales in some instances.null
scaleInvertReverses the Y axis scale so that the minimum value is at the top, instead of the bottom.false
scaleZerostartWhether the scale starts at zero or not.true
yminThe optional minimum Y scale value. If not specified then it will be zero.null
ymaxThe optional maximum Y scale value. If not specified then it will be calculated.null (It's calculated)
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 gutters) then you can enable this option. There's a demo of the outofboundsClip option here.false

Axis properties

PropertyDescriptionDefault
numxticksThe number of X tickmarks.null (linked to number of datapoints)
numyticksThe number of Y tickmarks.10
tickdirectionWhether the ticks are above or below the axis.-1 (-1 is below, 1 is above)
axisColorThe color of the axes.black
axisLinewidthThe linewidth of the axes.1
xaxisposThe position of the X axis. It can be either bottom, center or top.bottom
yaxisposSpecifies the Y axis position. Can be left or rightleft
noaxesWhether the axes are drawnfalse (the axes ARE drawn)
axesontopA minor option, this sets the axes to be redrawn after the chart has been drawn. This is only useful in a certain set of circumstances - the chart is filled and the line width is small.false
noendxtickWhen you're combining the Bar and Line charts, you may want to use this property to stop the end X tick from being drawn.false (the end tick IS drawn)
noendytickWhen you're combining the Bar and Line charts, you may want to use this property to stop the end Y tick from being drawn.false (the end tick IS drawn)

Zoom

PropertyDescriptionDefault
zoomFactorThis is the factor that the chart will be zoomed by (bigger values means more zoom)1.5
zoomFadeInWhether the zoomed canvas fades in or not. This also can be used to control the fade in for the zoom in thumbnail mode.true
zoomFadeOutWhether the zoomed canvas fades out or not. This also can be used to control the fade in for the zoom in thumbnail mode.true
zoomHdirThe horizontal direction of the zoom. Possible values are: left, center, rightright
zoomVdirThe vertical direction of the zoom. Possible values are: up, center, downdown
zoomDelayThe delay (in milliseconds) between frames.50
zoomFramesThe number of frames in the zoom animation.10
zoomShadowWhether or not the zoomed canvas has a shadow or not.true

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
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

PropertyDescriptionDefault
tickmarksWhat kind of tickmarks to use on the chart. This can be:
  • circle
  • filledcircle
  • endcircle
  • 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 now (10th August 2010) as well as a string, this can be an array of different tickmark styles.

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

null
tickmarksDotStrokeThis is the color of the filled part of the dot/borderedcircle style tickmarks.null (defaults to the line color)
tickmarksDotFillThis is the color of the stroked part of the dot/borderedcircle style tickmarks.null (defaults to the line color)
tickmarksDotLinewidthThis is the width of the line used when drawing the tickmarks.0
tickmarksImageHalignThis can be left, right or center and determines the horizontal alignment of the tickmark.center
tickmarksImageValignThis can be top, bottom or center and determines the vertical alignment of the tickmark.center
tickmarksImageOffsetxAfter the alignment has been applied, this is added to the X coordinate of the tickmark.0
tickmarksImageOffsetyAfter the alignment has been applied, this is added to the Y coordinate of the tickmark.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
variantAt present this can only be 3d, and gives a small 3D effect.null
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. Its 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 color to use when the canvas.null
combinedchartEffectSet 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() functionnull
combinedchartEffectOptionsThis 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
combinedchartEffectCallbackA function that runs when this objects effect has conpleted.null
dottedWhether the line (not the background grid) is dotted or not. This a new addition in January 2017 and is thanks to a submnission by Garagedfalse
dashedWhether the line (not the background grid) is dashed or not. This a new addition in January 2017 and is thanks to a submnission by Garagedfalse

 

Methods

 

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

 

obj.set(name, value)
An accessor that you can use to set the value 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,
            tickmarks: 'endcircle',
            labels: ['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 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;
            }

            // Start afresh
            RGraph.redraw();

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


                // Show the tooltip
                 RGraph.tooltip(
                    obj,
                    obj.get('labels')[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 gutter 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 coord for a value when you're doing custom drawing on the chart. It returns the coordinate for the max/min value if the given number is out of range.

 

obj.on(event, func)

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 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 color to rgba(0,0,0,0). Tooltips and other interactive features still work even though the line is not visible. You can give either an integer (the index of the relevant line), an array of line indexes, or no argument at all in which case all lines 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 show an upper and lower range for a particular point like this example page 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: {
        min: 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,
        tickmarks: 'circle',
        scaleZerostart: true,
        noxaxis: true
    }
}).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 with. Find out more here. In the same vein, you can have Y axes on both the left and right sides.

 

Alternative colors

Instead of a string stipulating the color, each element of the colors array can itself be a two element array, stipulating the up color, and the down color. To use alternating colors 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 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 colors 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 tickmarks

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

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

    /**
    * The function that is called once per tickmark, to draw it
    * 
    * @param object obj   The chart object
    * @param array  data  The entire line data
    * @param number value The individual points 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 color 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 here
    }
</script>

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

obj.set({tickmarks: 'image:foo.png'});     // Starts with image: prefix
obj.set({tickmarks: '/images/foo.png'});   // Starts with a /
obj.set({tickmarks: '../images/foo.png'}); // Starts with ../
obj.set({tickmarks: 'data: ...'});         // Starts with data: (for inline images)
obj.set({tickmarks: '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: {
            gutterLeft: 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>