About
RGraph is a JavaScript charts library based on HTML5 SVG and canvas. RGraph is mature (over 15 years old) and has a wealth of features making it an ideal choice to show charts on your website.

More »

 

License
RGraph can be used for free under the GPL or if that doesn't suit your situation there's an inexpensive (£99) commercial license available.

More »

 

Download
Get the latest version of RGraph (version 6.17) from the download page. There's also older versions available, minified files and links to cdnjs.com hosted libraries.

More »

The drawing API Marker3 object API reference


Usage example

View example on CodePen
<script>
    line = new RGraph.Line({
        id: 'cvs',
        data: [4,9,1,3,2,6,5],
        options: {
            spline: true,
            backgroundGridVlines:false,
            backgroundGridBorder:false,
            xaxis: false,
            yaxis: false,
            xaxisLabels: ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'],
            marginInner: 5,
            tickmarksStyle: 'endcircle',
            tickmarksSize: 10,
            colors: ['black'],
            textSize: 16
        }
    }).draw();

    x      = line.coords[2][0];
    y      = line.coords[2][1];
    radius = 25;

    marker3 = new RGraph.Drawing.Marker3({
        id: 'cvs',
        x: x,
        y: y,
        radius: radius,
        options: {
            colorsFill: 'green'
        }
    }).draw();
</script>

Properties

Color properties

Name: colorsFill
Description: 
The color used to fill the circle.
Default: white

Other text properties

Name: textAccessible
Description: 
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: false
Name: text
Description: 
This allows you to add custom text to your chart if you want to. There's a dedicated page that describes this option here.
Default: null

Miscellaneous properties

Name: highlightStyle
Description: 
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. It's passed the shape object as an argument.
Default: null
Name: highlightFill
Description: 
This is the color that the circle is highlighted in (the fill) when the tooltip is shown. Because this Marker is animated and is constantly being redrawn this setting doesn't have a visible effect.
Default: rgba(255,255,255,0.7)

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 easy to get hold of the marker when it has been clicked on or hovered over. It returns an object which has the following indexes available:
object The chart object.
x The center X coordinate of the marker.
y The center Y coordinate of the marker.
radius The radius of the marker.
dataset As there's only ever one element this is always zero.
index As there's only ever one element this is always zero.
sequentialIndex As there's only ever one element this is always zero.
tooltip If a tooltip is associated with the Marker3 object this will be it.id: strings are expanded for you (where the tooltip text is retrieved from the html tag with the matching ID).
Remember the Marker3 is animated so any drawing that you do on the marker will be cleared when the canvas is redrawn.
<script>
    marker3.onclick = function (e, shape)
    {
        marker3.on('draw',  function (obj)
        {
            obj.path(
                'lw 10 b a % % % 0 6.29 false s black f red',
                shape.x, shape.y, shape.radius
            );
        });
    }
</script>

obj.on(event, function)

This method can be used to set an event listener on an object. It operates similarly 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:

obj.on('draw', function (obj)
{
    // Put your event code here
});

The function is useful if you use method chaining when creating your charts:

obj = new RGraph.Drawing.Marker3({
    id: 'cvs',
}).on('draw', function (obj)
{
    // Put your draw event code here

}).on('click', function (e, shape)
{
    // Handle the click event

}).draw();

obj.exec(function)

The exec function is documented here.