Line chart documentation

  Read comments...
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.

 

Background

backgroundBarcolor1
The color of the background bars (1 of 2).
Default: rgba(0,0,0,0)

backgroundBarcolor2
The color of the background bars (2 of 2).
Default: rgba(0,0,0,0)

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

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

backgroundHbars
An 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.
Default: null

backgroundGridWidth
The width of the background grid.
Default: 1

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

backgroundGridAutofit
Instead of specifying a pixel width/height for the background grid, you can use autofit and specify how many horizontal and vertical lines you want.
Default: true

backgroundGridAutofitNumhlines
When using autofit this allows you to specify how many horizontal grid lines you want.
Default: 5

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

backgroundGridAutofitAlign
If 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.
Default: false

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

backgroundImage
If 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.
Default: null

backgroundImageStretch
By 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.
Default: true

backgroundImageX
The X position of the image. The coordinates are the top left corner of the image.
Default: null

backgroundImageY
The Y position of the image. The coordinates are the top left corner of the image.
Default: null

backgroundImageW
The width of the image. If you have a large canvas with many charts - you may need to specify this.
Default: null

backgroundImageH
The height of the image. If you have a large canvas with many charts - you may need to specify this.
Default: null

backgroundImageAlign
Instead of specifying the coordinates of the image, you can instead simply align it top, bottom, left or right. Examples are:

Default: null

backgroundImageAlpha
The alpha value (the opacity) of the image.
Default: 1

backdrop
When enabled this specifies that the line(s) will have a backdrop effect. You can control the transparency with the other backdrop settings).
Default: false

backdropSize
This controls the size/extent of the backdrop effect.
Default: 30

backdropAlpha
This controls how much transparency the backdrop effect has. It can go from 0 - 1.
Default: 0.2

backgroundColor
If 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.
Default: null

 

Labels and text

labelsAbove
Whether the values are shown in labels drawn above the line.
Default: false

labelsBold
Whether the labels are bold or not
Default: false

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

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

labelsColor
The color of the labels
Default: null (same as textColor)

labelsAboveSize
The size of the labels which are drawn above the line.
Default: 8

labelsAboveDecimals
The 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.
Default: null

labelsAboveColor
The text color of the labels
Default: Same as the text.color setting

labelsAboveBackground
The background color of the labels
Default: white

labelsAboveFont
The font used to render the labels
Default: Same as text.font

labelsAboveBorder
Whether the labels have a border or not
Default: true

labelsAboveOffsety
The Y offset of the label from the point on the line
Default: 5

labelsAboveUnitsPre
The units that appear BEFORE the label
Default: none

labelsAboveUnitsPost
The units that appear AFTER the label
Default: none

labelsAboveSpecific
This can be an array of (text) labels that you want to appear above the line instead of the values.
Default: null

labels
An array of the X labels for the chart.
Default: An empty array

labelsIngraph
An 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.
Default: null

ylabels
Can be true or false and determines whether the chart has Y axis labels.
Default: true

ylabelsCount
A 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.
Default: 5

ylabelsInside
This controls whether the Y labels are drawn inside the Y axis or not. If your labels are large, this may help.
Default: false

ylabelsInsideColor
If the Y labels are to be drawn inside the Y axis, this is used as the background color.
Default: rgba(255,255,255,0.5)

ylabelsSpecific
You 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.
Default: null

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

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

xlabelsInside
This 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.
Default: false

xlabelsInsideColor
If the X labels are to be drawn inside the X axis, this is used as the background color.
Default: rgba(255,255,255,0.5)

textSize
The size of the text (in points).
Default: 10

textAngle
The angle of the horizontal text labels (at the bottom of the chart). This can be from 90 to -90 degrees.
Default: 0 (Horizontal)

textFont
The font used to render the text.
Default: Arial

textColor
The color of the labels.
Default: black

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

 

Margins

gutterLeft
The left gutter of the chart, (the gutter is where the labels and title are)).
Default: 25

gutterRight
The right gutter of the chart, (the gutter is where the labels and title are).
Default: 25

gutterTop
The top gutter of the chart, (the gutter is where the labels and title are).
Default: 25

gutterBottom
The bottom gutter of the chart, (the gutter is where the labels and title are).
Default: 25

hmargin
The size of the horizontal margin. This is on the inside of the axes.
Default: 0

 

Colors

colors
An array of line colors.
Default: ['#f00', '#0f0', '', '#00f', '#f0f', '#ff0', '#0ff']

colorsAlternate
Set this to true if you want your line color(s) to be alternated. See note
Default: false

fillstyle
A 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.
Default: null

filled
Whether 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.
Default: false

filledAccumulative
When 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.


Default: true

filledRange
This is useful for indicating a range. Exactly two datasets are required, with the space between them filled. This is useful for indicating a range.
Default: false

filledRangeThreshold
When 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.
Default: null

filledRangeThresholdColors
This 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.
Default: ['red', 'green']

 

Shadow

shadow
Whether a drop shadow is applied.
Default: false

shadowColor
The color of the shadow.
Default: rgba(0,0,0,0.5)

shadowOffsetx
The X offset of the shadow.
Default: 2

shadowOffsety
The Y offset of the shadow.
Default: 2

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

 

Interactive features

tooltips
A numerically indexed array of tooltips that are shown when a bar is clicked. These can contain HTML.
Default: An empty array

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

tooltipsHighlight
Set this to false if you don't want your charts to be highlighted.
Default: true

tooltipsHotspotXonly
Set this to true if you want the tooltips to be triggered by the mouse X position only.
Default: false

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 tooltip DO NOT get hidden.
Default: false

tooltipsHotspotSize
The size of the hotspot area for tooltips.
Default: 5

crosshairs
If true, you will get a crosshair centering on the current mouse position.
Default: false

crosshairsLinewidth
This controls the linewidth of the crosshairs.
Default: 1

crosshairsColor
The color of the crosshairs.
Default: #333

crosshairsHline
This determines whether the horizontal crosshair is shown.
Default: true

crosshairsVline
This determines whether the vertical crosshair is shown.
Default: true

contextmenu
An array of context menu items. More information on context menus is here.
Default: [] (An empty array)

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

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

annotateLinewidth
This is the line width of the annotations.
Default: 1

resizable
Defaulting 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).
Default: false

resizeHandleBackground
With 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.
Default: null

resizableMaxwidth
This allows you to set a maximum width that the chart can be resized to.
Default: null

resizableMaxheight
This allows you to set a maximum height that the chart can be resized to.
Default: null

adjustable
Defaulting to false, this determines whether your bar chart will be adjustable.
Default: false

adjustableOnly
This 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.
Default: null

 

Titles

title
The title of the
Default: none

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

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

titleBold
Whather the title is bold or not.
Default: true

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

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

titleX
To give the exact X coordinate for the title - use this
Default: null

titleY
To give the exact Y coordinate for the title - use this
Default: null

titleColor
The color of the title.
Default: black

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

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

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

titleXaxisBold
This controls whether the X axis title is bold or not.
Default: true

titleXaxisColor
This controls the color of the X axis title.
Default: black

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

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

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

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

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

titleYaxisBold
This controls whether the Y axis title is bold or not.
Default: true

titleYaxisColor
This controls what color the Y axis is.
Default: black

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

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

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

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

 

Key

The key properties are documented on the key documentation page.

 

Scale

scaleFormatter
To 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);

Default: null

unitsPost
The units (if any) that the Y axis is measured in (gets appended to the number)
Default: none

unitsPre
The units (if any) that the Y axis is measured in (gets preppended to the number)
Default: none

scaleDecimals
Determines the precision of the numbers used as the scale.
Default: 0

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

scaleThousand
The character used as the thousand separator
Default: ,

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

scaleInvert
Reverses the Y axis scale so that the minimum value is at the top, instead of the bottom.
Default: false

scaleZerostart
Whether the scale starts at zero or not.
Default: true

ymin
The optional minimum Y scale value. If not specified then it will be zero.
Default: null

ymax
The optional maximum Y scale value. If not specified then it will be calculated.
Default: null (It's calculated)

outofbounds
Normally, out-of-bounds values are not drawn. By setting this to true you can change this behaviour.
Default: false

outofboundsClip
If 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.
Default: false

 

Axis properties

numxticks
The number of X tickmarks.
Default: null (linked to number of datapoints)

numyticks
The number of Y tickmarks.
Default: 10

tickdirection
Whether the ticks are above or below the axis.
Default: -1 (-1 is below, 1 is above)

axisColor
The color of the axes.
Default: black

axisLinewidth
The linewidth of the axes.
Default: 1

xaxispos
The position of the X axis. It can be either bottom, center or top.
Default: bottom

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

noaxes
Whether the axes are drawn
Default: false (the axes ARE drawn)

axesontop
A 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.
Default: false

noendxtick
When you're combining the Bar and Line charts, you may want to use this property to stop the end X tick from being drawn.
Default: false (the end tick IS drawn)

noendytick
When you're combining the Bar and Line charts, you may want to use this property to stop the end Y tick from being drawn.
Default: false (the end tick IS drawn)

 

Zoom

zoomFactor
This is the factor that the chart will be zoomed by (bigger values means more zoom)
Default: 1.5

zoomFadeIn
Whether the zoomed canvas fades in or not. This also can be used to control the fade in for the zoom in thumbnail mode.
Default: true

zoomFadeOut
Whether the zoomed canvas fades out or not. This also can be used to control the fade in for the zoom in thumbnail mode.
Default: true

zoomHdir
The horizontal direction of the zoom. Possible values are: left, center, right
Default: right

zoomVdir
The vertical direction of the zoom. Possible values are: up, center, down
Default: down

zoomDelay
The delay (in milliseconds) between frames.
Default: 50

zoomFrames
The number of frames in the zoom animation.
Default: 10

zoomShadow
Whether or not the zoomed canvas has a shadow or not.
Default: true

 

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

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

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

 

Miscellaneous

tickmarks
What kind of tickmarks to use on the chart. This can be:

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
Default: null

tickmarksDotStroke
This is the color of the filled part of the dot/borderedcircle style tickmarks.
Default: null (defaults to the line color)

tickmarksDotFill
This is the color of the stroked part of the dot/borderedcircle style tickmarks.
Default: null (defaults to the line color)

tickmarksDotLinewidth
This is the width of the line used when drawing the tickmarks.
Default: 0

tickmarksImageHalign
This can be left, right or center and determines the horizontal alignment of the tickmark.
Default: center

tickmarksImageValign
This can be top, bottom or center and determines the vertical alignment of the tickmark.
Default: center

tickmarksImageOffsetx
After the alignment has been applied, this is added to the X coordinate of the tickmark.
Default: 0

tickmarksImageOffsety
After the alignment has been applied, this is added to the Y coordinate of the tickmark.
Default: 0

stepped
Draws the line as stepped. Useful for showing stock performance for example.
Default: false

linewidth
The 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.
Default: 1

variant
At present this can only be 3d, and gives a small 3D effect.
Default: null

animationUnfoldX
This is used by the Unfold Line chart animation and dictates whether the X value is unfolded.
Default: false

animationUnfoldY
This is used by the Unfold Line chart animation and dictates whether the Y value is unfolded.
Default: true

animationUnfoldInitial
This 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.
Default: 2

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. 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
Default: null

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

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

spline
This 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.
Default: false

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

combinedchartEffect
Set 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
Default: null

combinedchartEffectOptions
This 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.
Default: null

combinedchartEffectCallback
A function that runs when this objects effect has conpleted.
Default: null

 

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;
        var co  = ca.getContext('2d');
        var obj = e.target.__object__;
      
        // This is the method which simplifies getting coordinates
        var point = obj.getShape(e);
      
      
        if (point) {
            
            ca.style.cursor = 'pointer';
            
            // Is 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
            RGraph.tooltip(ca, obj.get('labels')[point[3]], e.pageX, e.pageY, point[3]);

            // 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, 0);
            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>
Share RGraph
X

Comments