RGraph: HTML5 canvas graph library - Line chart documentation

The line graph, along with the bar chart, is probably the most configurable of all the charts available.

The example file is here.

    window.onload = function ()
        var data = [10,4,17,50,25,19,20,25,30,29,30,29];
        var line = new RGraph.Line("myLine", data);
        line.Set('chart.background.barcolor1', 'rgba(255,255,255,1)');
        line.Set('chart.background.barcolor2', 'rgba(255,255,255,1)');
        line.Set('chart.background.grid.color', 'rgba(238,238,238,1)');
        line.Set('chart.colors', ['rgba(255,0,0,1)']);
        line.Set('chart.linewidth', 2);
        line.Set('chart.filled', true);
        line.Set('chart.hmargin', 5);
        line.Set('chart.labels', ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']);
        line.Set('chart.border', 'rgba(255,255,255,1)');
        line.Set('chart.gutter', 40);

Combining the Line and Bar charts

You can combine the Bar and Line charts with a bit of magic. It's actually quite easy to do. Find out more here. In the same vain, you can have Y axes on both the left and right.

Available properties

You can use these properties to control how the bar graph apears. You can set them by using the Set() method. Eg:

myLine.Set('name', 'value');

chart.gutter The gutter of the graph. This is the bit of the graph that the labels are in.
Default: 25
chart.background.barcolor1 The color of the background bars (1 of 2).
Default: rgba(0,0,0,0)
chart.background.barcolor2 The color of the background bars (2 of 2).
Default: rgba(0,0,0,0)
chart.background.grid Whether to show the background grid or not.
Default: true
chart.background.grid.color The color of the background grid.
Default: #eee
chart.background.hbars 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
chart.background.grid.hsize The horizontal size of the grid.
Default: 25
chart.background.grid.vsize The vertical size of the grid.
Default: 25
chart.background.grid.width The width of the background grid.
Default: 1
chart.background.grid.border Determines whether a border line is drawn around the grid.
Default: true
chart.background.grid.hlines Determines whether to draw the horizontal grid lines.
Default: true
chart.background.grid.vlines Determines whether to draw the vertical grid lines.
Default: true
chart.colors An array of line colors.
Default: ['#f00', '#0f0', '', '#00f', '#f0f', '#ff0', '#0ff']
chart.linewidth The width of the line (ie the actual line on the line graph). 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
chart.border.color The color of the border of the graph. If you're not displaying the background grid, you will probably want to set this to false (ie turn it off).
Default: #090
chart.hmargin The size of the horizontal margin. This is on the inside of the axes.
Default: 0
chart.tickmarks What kind of tickmarks to use on the graph. This can be:
  • circle
  • filledcircle
  • endcircle
  • square
  • endsquare
  • filledsquare
  • filledendsquare
  • tick
  • halftick
  • endtick
  • cross
  • borderedcircle
  • arrow
  • filledarrow

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

Default: null
chart.xticks The number of X tickmarks.
Default: null (linked to number of datapoints)
chart.ticksize The size of the tick marks. This only affects certain styles of tickmarks.
Default: 3
chart.tickdirection Whether the ticks are above or below the axis.
Default: -1 (-1 is below, 1 is above)
chart.axis.color The color of the axes.
Default: black
chart.filled Whether the area under the graph is filled or not. This looks best when there is no horizontal margin.
Default: false
chart.filled.range 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.The line chart examples page demonstrates this in action.
Default: false
chart.xaxispos The position of the X axis. It can be either bottom or center.
Default: bottom
chart.yaxispos Specifies the Y axis position. Can be left or right.
Default: left
chart.text.size The size of the text (in points).
Default: 10
chart.text.angle The angle of the horizontal text labels (at the bottom of the graph). This can be one of three values - 0, 45 or 90.
Default: 0 (Horizontal)
chart.text.font The font used to render the text.
Default: Verdana
chart.text.color The color of the labels.
Default: black
chart.shadow If true a shadow will be applied to the line.
Default: false
chart.shadow.color The color of the shadow.
Default: rgba(0,0,0,0.5)
chart.shadow.offsetx The X offset in pixels for the shadow.
Default: 3
chart.shadow.offsety The Y offset in pixels for the shadow.
Default: 3
chart.shadow.blur The severity of the shadow blurring effect.
Default: 3
chart.tooltips These are tooltips for the line(s). It should be an array of tooltips. If you have multiple lines, simply pass multiple arrays to the Set() method.
Default: [] (An empty array)
chart.tooltip.effect The animated effect used for showing tooltips. Can be either fade or expand.
Default: fade
chart.tickmarks.dot.color This is the color of the BORDER around the dot/borderedcircle style tickmarks.
Default: #fff
chart.title The title of the chart.
Default: none
chart.title.vpos This allows you to completely override the vertical positioning of the title. It should be a number between 0 and 1, and is multiplied with the gutter and then used as the vertical position. It can be useful if you need to have a large gutter.
Default: null
chart.title.color The color of the title.
Default: black
chart.stepped Draws the line as stepped. Useful for showing stock performance for example.
Default: false
chart.key An array of key information.
Default: [] (An empty array)
chart.key.background The color of the key background. Typically white, you could set this to something like rgba(255,255,255,0.7) to allow people to see things behind it.
Default: white
chart.key.position Determines the position of the key.Either graph (default), or gutter.
Default: graph
chart.key.shadow Whether a small drop shadow is applied to the key.
Default: false
chart.noaxes Whether the axes are drawn
Default: false (the axes ARE drawn)
chart.units.post The units (if any) that the Y axis is measured in (gets appended to the number)
Default: none
chart.units.pre The units (if any) that the Y axis is measured in (gets preppended to the number)
Default: none
chart.scale.decimals Determines the precision of the numbers used as the scale.
Default: 0
chart.ymax The optional maximum Y scale value. If not specified then it will be calculated.
Default: null (It's calculated)
chart.crosshairs If true, you will get a crosshair centering on the current mouse position.
Default: false
chart.crosshairs.color The color of the crosshairs.
Default: #333
chart.contextmenu An array of context menu items. Unlike the bar chart, you CAN have context menus at the same time as tooltips. More information on context menus is here.
Default: [] (An empty array)
chart.annotatable Whether annotations are enabled for the chart (ie you can draw on the chart interactively.
Default: false
chart.annotate.color If you do not allow the use of the palette, then this will be the only color allowed for annotations.
Default: black
chart.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
chart.axesontop A minor option, this sets the axes to be redrawn after the graph has been drawn. This is only useful in a certain set of circumstances - the graph is filled and the line width is small.
Default: false
chart.variant At present this can only be 3d, and gives a small 3D effect.
Default: null
chart.zoom.mode Can be used to control whether the zoom is in thumbnail or canvas mode. Possible values are: thumbnail and canvas.
Default: canvas
chart.zoom.factor This is the factor that the graph will be zoomed by (bigger values means more zoom)
Default: 1.5
chart.zoom.fade.in 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
chart.zoom.fade.out 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
chart.zoom.hdir The horizontal direction of the zoom. Possible values are: left, center, right
Default: right
chart.zoom.vdir The vertical direction of the zoom. Possible values are: up, center, down
Default: down
chart.zoom.delay The delay (in milliseconds) between frames.
Default: 50
chart.zoom.frames The number of frames in the zoom animation.
Default: 10
chart.zoom.shadow Whether or not the zoomed canvas has a shadow or not.
Default: true
chart.zoom.thumbnail.width When the zoom is in thumbnail mode, this is the width (in pixels) of the thumbnail.
Default: 75
chart.zoom.thumbnail.height When the zoom is in thumbnail mode, this is the height (in pixels) of the thumbnail.
Default: 75
chart.ylabels Can be true or false and determines whether the chart has Y axis labels.
Default: true