Activity meter
Example
<script> activity = new RGraph.Activity({ id: 'cvs', min: 0, max: 100, value: [12,38,65], options: { width: 30, labelsCenter: true, marginLeft: 5, marginRight: 5, marginTop: 5, marginBottom: 5 } }).grow(); setInterval(function () { for (var i=0,rand=[]; i<3; ++i) { rand[i] = RGraph.random(-10,10); activity.value[i] += rand[i]; } activity.grow(); },2500); </script>
Properties
You can use these properties to control how the chart appears. You can set them by including them in the options section of the configuration as shown above.
- Chart configuration properties
- Margin properties
- Background properties
- Color properties
- Labels and text properties
- Interactive features properties
- Miscellaneous properties
Chart configuration properties
The X coordinate of the meter.
Default: null (the horizontal center of the
canvas
)centery
The Y coordinate of the meter.
Default: null (the vertical center of the
canvas
)radius
The
radius
of the chart.Default: null (this is generated based on the size of the
canvas
)width
This is the
width
of the circular bars that make up the chart.Default: null
Margin properties
The left margin of the chart.
Default: 15
marginRight
The right margin of the chart.
Default: 15
marginTop
The top margin of the chart.
Default: 15
marginBottom
The bottom margin of the chart.
Default: 15
marginInner
The margin on either side of the indicator bar.
Default: 1
Background properties
The color of the background grid.
Default: #666
backgroundGridCircles
Whether the background grid circular lines are enabled.
Default: false
backgroundGridCirclesCount
The number of background grid circular lines. By default, this number is dependent on how many values you're showing on the chart.
Default: null
backgroundGridRadials
Whether the background grid radial lines are enabled (the lines that emanate from the center and go outwards).
Default: true
backgroundGridRadialsCount
The number of background grid radial lines.
Default: 8
backgroundRings
Whether the background rings are drawn. These are the rings that serve as backgrounds to the bars.
Default: true
backgroundRingsColors
If you wish you can stipulate the exact colors for the background rings with this property..
Default: null
backgroundRingsAlpha
The
alpha
value (ie the transparency) of the colors of the background rings.Default: 0.5
Color properties
The background color of the
canvas
.Default: black
colors
The colors of the indicator bars. These can be solid colors or gradients.
Default: [#f45b5b, #90ee7e, #2b908f, red, green, blue, yellow, pink]
Labels and text properties
Property | Description | Default |
---|---|---|
textAccessible | A new feature in 2016 that allows you to use dom text in place of canvas text. It makes for a 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"> | false |
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 margins if you wish. | visible |
textAccessiblePointerevents | This controls whether the dom text responds to mouse-based events or not (it sets the pointer-events css property to none ). | true |
textFont | The font used to render the text. | Arial, Verdana, sans-serif |
textColor | The color of the label. | #aaa |
textSize | The size of the text (in points). | 12 |
textBold | Whether the text on the chart is bold or not. | false |
textItalic | Whether the text on the chart is italic or not. | false |
labels | Labels are placed to the left of the start of the bars (at the top middle). You can also give this option a string if you prefer and use formatted labels | [] (an empty array) |
labelsFont | The font used by the labels. | null |
labelsSize | The size of the labels. | null |
labelsColor | The color of the labels. | null |
labelsBold | Whether the labels are bold or not. | null |
labelsItalic | Whether the labels are italic or not. | null |
labelsBackgroundFill | With this you can give a color for the background fill to the labels. | null |
labelsBackgroundStroke | With this you can give a color for the background stroke to the labels. | null |
labelsOffsetx | This allows you finer-grained control in the horizontal direction over the text positioning if you need it. | 0 |
labelsOffsety | This allows you finer-grained control in the vertical direction over the text positioning if you need it. | 0 |
labelsFormattedDecimals | When using formatted labels this is the number of decimals that are applied to the %{value_formatted} macro. | 0 |
labelsFormattedPoint | When using formatted labels this is the decimal point character that's used with the %{value_formatted} macro. | . |
labelsFormattedThousand | When using formatted labels this is the thousand separator character that's used with the %{value_formatted} macro. | , |
labelsFormattedUnitsPre | When using formatted labels these are the units that are prepended to the number with the %{value_formatted} macro. | (an empty string) |
labelsFormattedUnitsPost | When using formatted labels these are the units that are appended to the number with the %{value_formatted} macro. | (an empty string) |
labelsCenter | Whether the center label is drawn or not. | false |
labelsCenterIndex | This is the index that corresponds to the index of the relevant ring's value that you want to display. | 0 |
labelsCenterFont | The font of the center label. | null |
labelsCenterSize | The size of the center label. | 50 |
labelsCenterColor | The color of the center label. | null |
labelsCenterBold | Whether the center label is bold or not. | null |
labelsCenterItalic | Whether the center label is italic or not. | null |
labelsCenterUnitsPre | Units that are prepended to the value. | [an empty string] |
labelsCenterUnitsPost | Units that are appended to the value. | [an empty string] |
labelsCenterDecimals | The number of decimals that are shown. | 0 |
labelsCenterPoint | The character that's used as the decimal point. | . |
labelsCenterThousand | The character that's used as the thousand separator. | , |
labelsCenterSpecific | If you want to specify the exact label to show you can do so with this property. | [an empty string] |
labelsCenterOffsetx | This allows you finer-grained control in the horizontal direction over the text positioning if you need it. | 0 |
labelsCenterOffsety | This allows you finer-grained control in the vertical direction over the text positioning if you need it. | 0 |
text | This allows you to add custom text to your chart if you want to. There's a dedicated page that describes this option here. | null |
A new feature in 2016 that allows you to use
dom
text in place of canvas
text. It makes for a 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
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 margins 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
textFont
The font used to render the text.
Default: Arial, Verdana, sans-serif
textColor
The color of the label.
Default: #aaa
textSize
The size of the text (in points).
Default: 12
textBold
Whether the text on the chart is bold or not.
Default: false
textItalic
Whether the text on the chart is italic or not.
Default: false
labels
Labels are placed to the left of the start of the bars (at the top middle). You can also give this option a string if you prefer and use formatted labels
Default: [] (an empty array)
labelsFont
The font used by the labels.
Default: null
labelsSize
The size of the labels.
Default: null
labelsColor
The color of the labels.
Default: null
labelsBold
Whether the labels are bold or not.
Default: null
labelsItalic
Whether the labels are italic or not.
Default: null
labelsBackgroundFill
With this you can give a color for the background fill to the labels.
Default: null
labelsBackgroundStroke
With this you can give a color for the background stroke to the labels.
Default: null
labelsOffsetx
This allows you finer-grained control in the horizontal direction over the text positioning if you need it.
Default: 0
labelsOffsety
This allows you finer-grained control in the vertical direction over the text positioning if you need it.
Default: 0
labelsFormattedDecimals
When using formatted labels this is the number of decimals that are applied to the
%{value_formatted}
macro.Default: 0
labelsFormattedPoint
When using formatted labels this is the decimal point character that's used with the
%{value_formatted}
macro.Default: .
labelsFormattedThousand
When using formatted labels this is the thousand separator character that's used with the
%{value_formatted}
macro.Default: ,
labelsFormattedUnitsPre
When using formatted labels these are the units that are prepended to the number with the
%{value_formatted}
macro.Default: (an empty string)
labelsFormattedUnitsPost
When using formatted labels these are the units that are appended to the number with the
%{value_formatted}
macro.Default: (an empty string)
labelsCenter
Whether the center label is drawn or not.
Default: false
labelsCenterIndex
This is the index that corresponds to the index of the relevant ring's value that you want to display.
Default: 0
labelsCenterFont
The font of the center label.
Default: null
labelsCenterSize
The size of the center label.
Default: 50
labelsCenterColor
The color of the center label.
Default: null
labelsCenterBold
Whether the center label is bold or not.
Default: null
labelsCenterItalic
Whether the center label is italic or not.
Default: null
labelsCenterUnitsPre
Units that are prepended to the value.
Default: [an empty string]
labelsCenterUnitsPost
Units that are appended to the value.
Default: [an empty string]
labelsCenterDecimals
The number of decimals that are shown.
Default: 0
labelsCenterPoint
The character that's used as the decimal point.
Default: .
labelsCenterThousand
The character that's used as the thousand separator.
Default: ,
labelsCenterSpecific
If you want to specify the exact label to show you can do so with this property.
Default: [an empty string]
labelsCenterOffsetx
This allows you finer-grained control in the horizontal direction over the text positioning if you need it.
Default: 0
labelsCenterOffsety
This allows you finer-grained control in the vertical direction over the text positioning if you need it.
Default: 0
text
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
Interactive features properties
Property | Description | Default |
---|---|---|
tooltips | A numerically indexed array of tooltips that are shown when a bar is clicked. These can contain html . | null |
tooltipsEffect | The effect used for showing tooltips. Can be either slide fade or none . | slide |
tooltipsEvent | This is the event that triggers the tooltips. It can be either click or mousemove . | click |
tooltipsOverride | If you wish to handle showing tooltips yourself, this should be a function that does just that. There's more information on the tooltips documentation page. | null |
tooltipsHighlight | Set this to false if you don't want your charts to be highlighted. | true |
tooltipsFormattedPoint | When using formatted tooltip strings this is used as the point when using the %{value_formatted} option. | . |
tooltipsFormattedThousand | When using formatted tooltip strings this is used as the thousand separator when using the %{value_formatted} option. | , |
tooltipsFormattedDecimals | When using formatted tooltip strings this specifies the number of decimals when using the %{value_formatted} option. | 0 |
tooltipsFormattedUnitsPre | When using formatted tooltip strings these units are prepended to the number when using the %{value_formatted} option. | (an empty string) |
tooltipsFormattedUnitsPost | When using formatted tooltip strings these units are appended to the number when using the %{value_formatted} option. | (an empty string) |
tooltipsFormattedKeyColors | When using formatted tooltip strings you can give specific colors for the %{key} option to use. | null |
tooltipsFormattedKeyColorsShape | This is the shape that's used in the tooltip key. It can be square or circle | square |
tooltipsFormattedKeyColorsCss | By using this property you can add css values to the key color shape that appears in the tooltip key. Note the property name is "color" and not "colors" like previous properties. It should be an object of css properties like this: tooltipsFormattedKeyColorsCss : { border: "1px solid #ddd"; } | null |
tooltipsFormattedKeyLabels | When using formatted tooltip strings these are the labels that are displayed. | [] (an empty array) |
tooltipsFormattedListType | With this property you can switch between an unordered list (the default) and an ordered list. Possible values are ul and ol . | ul |
tooltipsFormattedListItems | This should be a two-dimension array of the list items that are to be shown for all of the tooltips. An example of this property is:tooltipsFormattedListItems: [ ['Bill','Jerry','Berty'], // First tooltip ['Gill','Carrie','Lucy'], // Second tooltip ['Pob','Nobby','Hilda'] // Third tooltip ]You can use css to style this list - for example:.RGraph_tooltip ul#rgraph_formatted_tooltips_list li { text-align: left; color: yellow; } | null |
tooltipsFormattedTableHeaders | When showing a table in the tooltips this can be an array of headers for the table. These are added to the tooltip using th tags. | null |
tooltipsFormattedTableData | This is the data that is added to the table. This is a 3-dimensional array so it's easy to make a mistake. See the example, copy the code from it and then modify it suit. You'll create fewer bugs this way. | null) |
tooltipsPointer | By default the tooltips have a small triangular pointer that points to the shape that was clicked on. You can turn this off with this property. | true |
tooltipsPointerCss | If you want any css values applied to the tooltips pointer (for example a css border) then specify an object containing those values to this property. For example: tooltipsPointerCss: { borderLeft: 'gray 2px solid', borderBottom: 'gray 2px solid' } | null |
tooltipsPointerOffsetx | This allows you to adjust the vertical position of the tooltips pointer. | 0 |
tooltipsPointerOffsety | This allows you to adjust the vertical position of the tooltips pointer (for example, if you add a border you may need to move it down slightly). | 0 |
tooltipsPositionStatic | The new default (as of August 2020) is for tooltips to be positioned statically and not be dependent on the mouse position. If you don't want this for whatever reason, you can disable it with this setting. When you set it to false tooltips are positioned next to the mouse pointer. | true |
tooltipsCss | If you want to specify some css that gets applied to all of the tooltips, but don't want to use the RGraph.tooltips.style object (which gets applied to all of the tooltips on the page for every chart) you can use this property to give some per-object css for the tooltips. These are css styles that get applied to all of the tooltips for the specific object only. It should look like this:tooltipsCss: { fontFamily: 'Verdana', fontSize: '20pt', backgroundColor: 'black', color: 'white' } | null |
tooltipsCssClass | This is the name of the css class the chart uses. | RGraph_tooltip |
tooltipsOffsetx | This property allows you to shift the tooltips left or right. | 0 |
tooltipsOffsety | This property allows you to shift the tooltips up or down. | 0 |
tooltipsHotspotIgnore | This can be a number of things and can be used to ignore certain tooltip hotspots - which can allow charts to the rear to be clickable. There's an example of this in the download archive called pie-tooltipshotspotignore.html . You can use the transparent color to allow the rear chart to be seen in such a case. It can be:
| null |
contextmenu | An array of context menu items. More information about context menus is here. | null |
annotatable | Whether annotations are enabled for the chart (ie you can draw on the chart interactively. | false |
annotatableColor | If you do not allow the use of the palette, then this will be the only color allowed for annotations. | black |
annotatableLinewidth | This is the linewidth of the annotations. | 1 |
adjustable | Defaulting to false, this determines whether your meter will be adjustable (click the bars and drag them). | false |
A numerically indexed array of tooltips that are shown when a bar is clicked. These can contain
html
.Default: null
tooltipsEffect
The effect used for showing tooltips. Can be either
slide
fade
or none
.Default: slide
tooltipsEvent
This is the event that triggers the tooltips. It can be either
click
or mousemove
.Default: click
tooltipsOverride
If you wish to handle showing tooltips yourself, this should be a function that 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
tooltipsFormattedPoint
When using formatted tooltip strings this is used as the point when using the
%{value_formatted}
option.Default: .
tooltipsFormattedThousand
When using formatted tooltip strings this is used as the thousand separator when using the
%{value_formatted}
option.Default: ,
tooltipsFormattedDecimals
When using formatted tooltip strings this specifies the number of decimals when using the
%{value_formatted}
option.Default: 0
tooltipsFormattedUnitsPre
When using formatted tooltip strings these units are prepended to the number when using the
%{value_formatted}
option.Default: (an empty string)
tooltipsFormattedUnitsPost
When using formatted tooltip strings these units are appended to the number when using the
%{value_formatted}
option.Default: (an empty string)
tooltipsFormattedKeyColors
When using formatted tooltip strings you can give specific colors for the
%{key}
option to use.Default: null
tooltipsFormattedKeyColorsShape
This is the shape that's used in the tooltip key. It can be
square
or circle
Default: square
tooltipsFormattedKeyColorsCss
By using this property you can add
css
values to the key color shape that appears in the tooltip key. Note the property name is "color" and not "colors" like previous properties. It should be an object of css
properties like this: tooltipsFormattedKeyColorsCss : { border: "1px solid #ddd"; }
Default: null
tooltipsFormattedKeyLabels
When using formatted tooltip strings these are the labels that are displayed.
Default: [] (an empty array)
tooltipsFormattedListType
With this property you can switch between an unordered list (the default) and an ordered list. Possible values are
ul
and ol
.Default: ul
tooltipsFormattedListItems
This should be a two-dimension array of the list items that are to be shown for all of the tooltips. An example of this property is:
tooltipsFormattedListItems: [ ['Bill','Jerry','Berty'], // First tooltip ['Gill','Carrie','Lucy'], // Second tooltip ['Pob','Nobby','Hilda'] // Third tooltip ]You can use
css
to style this list - for example:.RGraph_tooltip ul#rgraph_formatted_tooltips_list li { text-align: left; color: yellow; }
Default: null
tooltipsFormattedTableHeaders
When showing a
table
in the tooltips this can be an array of headers for the table. These are added to the tooltip using th
tags.Default: null
tooltipsFormattedTableData
This is the data that is added to the table. This is a 3-dimensional array so it's easy to make a mistake. See the example, copy the code from it and then modify it suit. You'll create fewer bugs this way.
Default: null)
tooltipsPointer
By default the tooltips have a small triangular pointer that points to the shape that was clicked on. You can turn this off with this property.
Default: true
tooltipsPointerCss
If you want any
css
values applied to the tooltips pointer (for example a css
border) then specify an object containing those values to this property. For example: tooltipsPointerCss: { borderLeft: 'gray 2px solid', borderBottom: 'gray 2px solid' }
Default: null
tooltipsPointerOffsetx
This allows you to adjust the vertical position of the tooltips pointer.
Default: 0
tooltipsPointerOffsety
This allows you to adjust the vertical position of the tooltips pointer (for example, if you add a border you may need to move it down slightly).
Default: 0
tooltipsPositionStatic
The new default (as of August 2020) is for tooltips to be positioned statically and not be dependent on the mouse position. If you don't want this for whatever reason, you can disable it with this setting. When you set it to
false
tooltips are positioned next to the mouse pointer.Default: true
tooltipsCss
If you want to specify some
css
that gets applied to all of the tooltips, but don't want to use the RGraph.tooltips.style
object (which gets applied to all of the tooltips on the page for every chart) you can use this property to give some per-object css
for the tooltips. These are css
styles that get applied to all of the tooltips for the specific object only. It should look like this:tooltipsCss: { fontFamily: 'Verdana', fontSize: '20pt', backgroundColor: 'black', color: 'white' }
Default: null
tooltipsCssClass
This is the name of the
css
class the chart uses.Default: RGraph_tooltip
tooltipsOffsetx
This property allows you to shift the tooltips left or right.
Default: 0
tooltipsOffsety
This property allows you to shift the tooltips up or down.
Default: 0
tooltipsHotspotIgnore
This can be a number of things and can be used to ignore certain tooltip hotspots - which can allow charts to the rear to be clickable. There's an example of this in the download archive called
pie-tooltipshotspotignore.html
. You can use the transparent
color to allow the rear chart to be seen in such a case. It can be:
- A single
boolean
value (ietrue
orfalse
) to enable or disable all of the hotspots -true
means the hotspot will be ignored - A single number (the zero-indexed number corresponding to the hotspot to ignore)
- An array of numbers (the numbers are the indexes of hotspots to ignore)
- An array of
boolean
true
orfalse
values - the position of these values correspond to the index(es) of the segments to ignore (for example[false, false, true, false, false]
-true
means the corresponding hotspot will be ignored)
Default: null
contextmenu
An array of context menu items. More information about context menus is here.
Default: null
annotatable
Whether annotations are enabled for the chart (ie you can draw on the chart interactively.
Default: false
annotatableColor
If you do not allow the use of the palette, then this will be the only color allowed for annotations.
Default: black
annotatableLinewidth
This is the
linewidth
of the annotations.Default: 1
adjustable
Defaulting to false, this determines whether your meter will be adjustable (click the bars and drag them).
Default: false
Miscellaneous properties
Property | Description | Default |
---|---|---|
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. As of version 5.23 you can also set this to invert as well. If you do this on a dark background you may find that you need to change the highlightFill color setting as well. | null |
highlightStroke | If you use tooltips, this controls the color of the highlight stroke. | rgba(0,0,0,0) |
highlightFill | If you use tooltips, this controls the color of the highlight fill. | rgba(255,255,255,0.5) |
icons | This can be an array of filenames (including their paths) of icons that are placed at the start of each bar. Eg ['/images/first.png', '/images/second.png', '/images/third.png'] | [] |
iconsWidth | With this you can give a specific width for the images. | null |
iconsHeight | With this you can give a specific height for the images. | null |
iconsOffsetx | This should be a number (either positive or negative) that is added to the X coordinate of the image. | 0 |
iconsOffsety | This should be a number (either positive or negative) that is added to the Y coordinate of the image. | 0 |
ends | This determines whether the ends of the bars will be round or straight. Possible values are: round straight and square | round |
clearto | This is used in animations and effects as the default color to use when clearing the canvas . | null |
responsive | This option is new to the July 2023 release (v6.13) and allows you to inline the responsive configuration instead of appending it on to the end of the object it as a function. The documentation and demo pages have been updated to use this new option. You can read more about the responsive feature by reading the responsive configuration page. | null |
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. As of version 5.23 you can also set this to invert
as well. If you do this on a dark background you may find that you need to change the highlightFill
color setting as well.Default: null
highlightStroke
If you use tooltips, this controls the color of the highlight stroke.
Default: rgba(0,0,0,0)
highlightFill
If you use tooltips, this controls the color of the highlight fill.
Default: rgba(255,255,255,0.5)
icons
This can be an array of filenames (including their paths) of icons that are placed at the start of each bar. Eg ['/images/first.png', '/images/second.png', '/images/third.png']
Default: []
iconsWidth
With this you can give a specific width for the images.
Default: null
iconsHeight
With this you can give a specific height for the images.
Default: null
iconsOffsetx
This should be a number (either positive or negative) that is added to the X coordinate of the image.
Default: 0
iconsOffsety
This should be a number (either positive or negative) that is added to the Y coordinate of the image.
Default: 0
ends
This determines whether the ends of the bars will be round or straight. Possible values are:
round
straight
and square
Default: round
clearto
This is used in animations and effects as the default color to use when clearing the
canvas
.Default: null
responsive
This option is new to the July 2023 release (v6.13) and allows you to inline the responsive configuration instead of appending it on to the end of the object it as a function. The documentation and demo pages have been updated to use this new option. You can read more about the responsive feature by reading the responsive configuration page.
Default: null
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 which bar 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 |
y |
The center Y coordinate |
angleStart |
The start angle of the segment. |
angleEnd |
The end angle of the segment. |
radiusInner |
The inside radius of the segment. |
radiusOuter |
The outside radius of the segment. |
label |
The relevant label for this ring. |
tooltip |
If a tooltip is associated with this bar or segment this will be it. id:
strings are expanded for you (where the tooltip text is retrieved from the html
tag with the matching ID).
|
dataset |
This is always zero. |
index |
The zero-indexed numerical index of the bar. |
sequentialIndex |
The zero-indexed sequential index of the bar. |
<script>
obj.canvas.onclick = function (e)
{
RGraph.redraw();
var canvas = e.target,
obj = canvas.__object__,
shape = obj.getShape(e);
if (shape) {
var x = shape.x,
y = shape.y,
start = shape.angleStart,
end = shape.angleEnd,
radiusInner = shape.radiusInner,
radiusInner = shape.radiusOuter;
obj.path(
'b a % % % % % false a % % % % % true s black f red',
x, y, radiusInner, start, end,
x, y, radiusOuter, end, start
);
}
}
</script>
obj.getValue(event)
This method can be used to get the value at a particular point when you click on the chart. An example:
obj.canvas.onclick = function (e)
{
var obj = e.target.__object__;
var value = obj.getValue(e);
// ...
}
obj.getAngle(value)
This method will return you an appropriate angle for the given value.
obj.getIndexByRadius(radius)
This method will return the index that corresponds to the ring that you're currently hovering over or clicking on.
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 event code here
});
The function is useful if you use method chaining when creating your charts:
var obj = new RGraph.Activity({ id: 'cvs', min: 0, max: 100, value: [25,35,46], options: { } }).on('draw', function (e, shape) { // Put the draw event code here }) .on('click', function (e, shape) { // Handle the click event }).draw();
obj.exec(function)
The exec function is documented here.
obj.responsive(configuration)
The responsive
function helps your charts
respond to different browser window sizes and screen
resolutions. For example, for smaller screens, you
might want to have angled labels or show shorter
versions of them completely.
Update: There is now the responsive configuration option available to you and this is now the preferred method of configuration.
The responsive function and configuration option are documented on their own page here.
Events
RGraph supports custom events that allow you to easily add interactivity to your charts if required. The following events are available:
adjustbegin
This event fires at the start of adjusting - like the standardmousedown
event.adjust
This event fires (repeatedly) during adjusting - like the standardmousemove
event.adjustend
This event fires at the end of adjusting - like the standardmouseup
event.annotatebegin
This event fires at the start of annotating - like the standardmousedown
event.annotate
This event fires (repeatedly) during annotating - like the standardmousemove
event.annotateend
This event fires at the end of annotating - like the standardmouseup
event.annotateclear
This event fires at the end of theRGraph.clearAnnotations
function.beforeclear
This event fires at the start of theRGraph.clear
function.clear
This event fires at the end of theRGraph.clear
function.click
This is similar to the standardcanvas
click
event but this only fires when you click on a bar - not the wholecanvas
.beforecontextmenu
This event fires when you have the contextmenu enabled and it is about to appear.contextmenu
This event fires when you have the contextmenu enabled and it has been displayed.beforedraw
This event fires at the start of thedraw
method before anything has been done.firstdraw
This event fires at the end of thedraw
function - but only the first time that thedraw
function is called.draw
This event fires at the end of thedraw
function.mousemove
This event is similar to the standardmousemove
event but only fires when you move the mouse over a bar on the chart.mouseover
This event is similar to the standardmouseover
event but only fires when you move the mouse over a bar on the chart.mouseout
This event is similar to the standardmouseout
event but only fires when you move the mouse away from a bar on the chart that you've previously hovered over.beforetooltip
This event fires at the start of the tooltip showing process.tooltip
This event fires after a tooltip has been shown.
new RGraph.Activity({ id: 'cvs', min: 0, max: 100, value:[26,35,34], options: { } }).on('draw', function (obj) { console.log('The draw event has fired'); }).draw();
Effects
These effects are available and can be used instead of thedraw
function. There are also generic effects available which
you can see here: Generic effects and transitions
- The
grow
effect (effects-activity-grow.html
in the download archive)
<script> // // Optional callback function that's called when the effect is complete // function myCallback (obj) { // ... } obj = new RGraph.Activity({ id: 'cvs', min: 0, max: 100, value: 56, options: { } }).grow({frames: 60}, myCallback) </script>