Segmented donut chart API reference
Example
<script> segmented = new RGraph.Segmented({ id: 'cvs', min: 0, max: 100, value: 67, options: { width: '-20', labelsCenterUnitsPost: '%' } }).roundRobin({frames: 90}); segmented.canvas.onclick = function (e) { var value = segmented.getValue(e); segmented.value = value; segmented.grow(); } </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
- Color properties
- Labels and text properties
- Interactive features properties
- Miscellaneous properties
Chart configuration properties
Segmented donut
using this instead of the margins. As well as a number, that gives the exact coordinate of the center position of the chart, this can also be a string
like this: centerx: '+25'
or this: centerx: '-40'
which is then used to adjust the calculated coordinate.Segmented donut
using this instead of the margins. As well as a number, that gives the exact coordinate of the center position of the chart, this can also be a string
like this: centery: '+25'
or this: centery: '-40'
which is then used to adjust the calculated coordinate.Segmented donut
using this instead of the margins. As well as a number, that gives the exact size of the chart, this can also be a string
like this: radius: '+25'
or this: radius: '-40'
which is then used to adjust the calculated coordinate.Margin properties
Color properties
Labels and text properties
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>
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.dom
text responds to mouse-based events or not (it sets the pointer-events
css
property to none).%{value_formatted}
macro.%{value_formatted}
macro.%{value_formatted}
macro.%{value_formatted}
macro.%{value_formatted}
macro.Interactive features properties
Miscellaneous properties
canvas
.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.getValue(event or angle)
This method can be used to get the value at a particular point when
you click on the chart (or for a specific angle that you give, measured in radians
). An example:
obj.canvas.onclick = function (e) { var obj = e.target.__object__; var value = obj.getValue(e); // var value = obj.getValue(angle); // Provide an angle to the function instead of an event object // ... }
obj.getAngle(value or event)
This method will return you an appropriate angle for the given value (or event object).
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.Segmented({ id: 'cvs', min: 0, max: 100, value: 56, options: { } }).on('draw', function (e, shape) { // Put the draw event code here }) .on('draw', function (e, shape) { // Handle the draw event with another function }).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.
The coordinates properties
There's only the coordinates of the text available to
in regards to coordinates that are maintained for you
because there are no selectable ares on the
Segmented Meter chart
-
obj.coordsText
This holds the coordinates of all of the text that has been added to the chart. Even if the text is blank (ie no text) then the coordinates will be added to this variable.
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.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.
new RGraph.Segmented({ id: 'cvs', min: 0, max: 100, valllue: 45, 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
There's a stopAnimation()
function that you can
use to stop an animation immediately if you need to.
There's a line chart demo called
demos/line-effects-stop-animation.html
in
the download archive
that demonstrates the use of this function.
- The
grow
effect (effects-segmented-grow.html
in the download archive) - The
roundRobin
effect (effects-segmented-roundRobin.html
in the download archive)
<script> // // Optional callback function that's called when the effect is complete // function myCallback (obj) { // ... } segmented = new RGraph.Segmented({ id: 'cvs', min: 0, max: 100, value: 56, options: { marginLeft: 35 } }).roundRobin({frames: 60}, myCallback); setInterval(function () { segmented.value = segmented.value + RGraph.random(-10,10); segmented.grow(); }, 2500); </script>