The drawing API marker2 object

Summary: The drawing API marker2 object can be added to your chart and provides a way for you to bring attention to a point or provide extra information to your users.

[No canvas support]

The marker2 object allows you to add extra information to your charts in the form of markers. These markers can then give even more information in the form of tooltips or by using the event properties.


Usage example

<script>
    line = new RGraph.Line({
        id: 'cvs',
        data: [4,9,1,3,2,6,5],
        options: {
            xaxisLabels: ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'],
            marginInner: 5,
            colors: ['black'],
            tooltips: ['A'],
            marginBottom: 35,
            shadow: false,
            tickmarksStyle: 'none',
            spline: true
        }
    }).draw();

    x = line.coords[3][0];
    y = line.coords[3][1];

    new RGraph.Drawing.Marker2({
        id: 'cvs',
        x: x,
        y: y,
        text: 'Note',
        options: {
            tooltips: ['<b>Note</b><br />Extra information can be displayed'],
            highlightFill: 'rgba(255,0,0,0.5)',
            shadow: false
        }
    }).draw();
</script>

Properties

Color properties

PropertyDescriptionDefault
colorsStrokeThe color used to stroke the circle.transparent
colorsFillThe color used to fill the circle.red
colorsStroke
The color used to stroke the circle.
Default: transparent

colorsFill
The color used to fill the circle.
Default: red

Text properties

PropertyDescriptionDefault
textFontThis is the font that the text is rendered in.Arial, Verdana, sans-serif
textSizeThe size of the text.12
textColorThe color that the text is rendered in.black
textBoldWhether the text is bold or not.false
textItalicWhether the text is italic or not.false
textFont
This is the font that the text is rendered in.
Default: Arial, Verdana, sans-serif

textSize
The size of the text.
Default: 12

textColor
The color that the text is rendered in.
Default: black

textBold
Whether the text is bold or not.
Default: false

textItalic
Whether the text is italic or not.
Default: false

Shadow properties

PropertyDescriptionDefault
shadowThis controls whether the shadow is enabled or not.false
shadowColorThe color of the shadow.gray
shadowOffsetxThe X offset that the shadow is drawn at.3
shadowOffsetyThe Y offset that the shadow is drawn at.3
shadowBlurThe severity of the shadow blur.5
shadow
This controls whether the shadow is enabled or not.
Default: false

shadowColor
The color of the shadow.
Default: gray

shadowOffsetx
The X offset that the shadow is drawn at.
Default: 3

shadowOffsety
The Y offset that the shadow is drawn at.
Default: 3

shadowBlur
The severity of the shadow blur.
Default: 5

Interactive features properties

PropertyDescriptionDefault
tooltipsThe tooltip for the circle. Even though you can only have one - this should still be an array: obj.set('tooltips', ['The tooltip']);null
tooltipsEventThis can be click or mousemove and controls what event is used to trigger the tooltip.click
tooltipsHighlightThis stipulates whether the circle will be highlighted when the tooltip is shown.true
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 the tooltip DOES NOT get hidden.false
tooltips
The tooltip for the circle. Even though you can only have one - this should still be an array: obj.set('tooltips', ['The tooltip']);
Default: null

tooltipsEvent
This can be click or mousemove and controls what event is used to trigger the tooltip.
Default: click

tooltipsHighlight
This stipulates whether the circle will be highlighted when the tooltip is shown.
Default: true

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

Miscellaneous properties

PropertyDescriptionDefault
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.null
highlightStrokeThis is the color that the circle is highlighted (the stroke) in when the tooltip is shown.black
highlightFillThis is the color that the circle is highlighted in (the fill) when the tooltip is shown.#fc
linewidthThis is the linewidth used to draw the marker.2
voffsetThis allows you to control how "high" the flag is from the bottom of the "flag pole".20
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. It's passed the shape object as an argument.
Default: null

highlightStroke
This is the color that the circle is highlighted (the stroke) in when the tooltip is shown.
Default: black

highlightFill
This is the color that the circle is highlighted in (the fill) when the tooltip is shown.
Default: #fc

linewidth
This is the linewidth used to draw the marker.
Default: 2

voffset
This allows you to control how "high" the flag is from the bottom of the "flag pole".
Default: 20

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 X coordinate for the marker.
Y The Y coordinate for the marker.
width The width of the marker.
height The height 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 Marker2 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).
<script>
    marker2.canvas.onclick = function (e)
    {
        RGraph.redraw();
    
        var canvas = e.target,
            obj    = canvas.__object__,
            shape  = obj.getShape(e);

        if (shape) {            
            // Highlight the main body of the Marker2 object.
            RGraph.path({
                object: obj,
                  path: 'lw 10 b r % % % % s black f rgba(255,0,0,0.25)',
                  args: [shape.x, shape.y, shape.width, shape.height]
            });
        }
    }
</script>

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:

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.Marker2({
    id: 'cvs',
    x: 100,
    y: 100,
    text: 'Note',
}).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.

Custom RGraph events that are available

Custom RGraph events are events that RGraph fires when certain actions occur. There is a more comprehensive list of these events here . Here's some example code that show you how to add these events to your chart.

There's more documentation about events available here: Summary of events documentation

<script>
    marker2 = new RGraph.Drawing.Marker2({
        id: 'cvs',
        x: 50,
        y: 50,
        text: 'Some example text!',
        options: {
        }
    }).draw().on('click', function (e, shape)
    {
        // Add your click event listener code here

    }).on('mousemove', function (e, shape)
    {
        // Add your mousemove event listener code here

    }).on('mouseover', function (e, shape)
    {
        // Add your mouseover event listener code here

    }).on('mouseout', function (obj)
    {
        // Add your mouseout event listener code here
    });
</script>