Segmented donut chart API reference
Example
<script> seg = new RGraph.SVG.Segmented({ id: 'chart-container', min: 0, max: 100, value: 63, options: { width: 60, labelsCenterDecimals: 1 } }).roundRobin(); var d = 2500; setTimeout(f = function () { seg.value = seg.value + RGraph.SVG.random({min: -7, max: 5}); seg.grow(); setTimeout(f, d); }, d); </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
- Other properties
Chart configuration properties
Segmented donut chart
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 chart
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 chart
using this instead of the margins. As well as a number, that gives the exact radius 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
%{value_formatted}
macro.%{value_formatted}
macro.%{value_formatted}
macro.%{value_formatted}
macro.%{value_formatted}
macro.Other properties
svg
zoom feature, added in version 6.19
, allows you to zoom in on a certain area of your chart and then pan around by dragging the zoom. You can also increase or decrease the zoom level by using your mousewheel if you have one. You can read a documentation page about the SVG zoom feature here.Methods
obj.get(name)
This can be used to get properties if necessary. It's normally used after the chart is drawn if you need to get parameters (if you're doing custom coding for example).
obj.set(name, value)
This can be used to set properties if necessary. It's normally used after the chart is drawn if you need to set additional parameters or change them.
obj.on(event, handler)
This function adds an event listener (such as beforedraw
or
draw
) to the chart object. For example:
obj.on('draw', function (obj)
{
// Put your code here
});
obj.exec(func)
This function can be used to execute a function (immediately). It's not event-based
(ie it doesn't run when something happens) - it just runs immediately - and only once.
You might use it when you need to get something from the chart when it's drawn and
then call the redraw function. Because this function only runs once the RGraph.SVG.redraw
function would not cause a loop - which would happen if you used the draw
event.
obj.exec(function (obj)
{
// Put your code 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.
obj.getAngle(event or value)
When you click on the chart this method can be used to get the corresponding angle.
Angles are measured in radians
and go from (approximately) -(Math.PI / 2)
(middle top) to
1.5 * Math.PI
. Example usage is:
<script>
seg = new RGraph.SVG.Segmented({
id: 'chart-container',
min: 0,
max: 100,
value: 63,
options: {
width: 60,
labelsCenterDecimals: 1
}
}).draw();
seg.container.onclick = function (e)
{
var angle = seg.getAngle(e);
// var angle = seg.getAngle(51); // You can also pass the function a value too
alert(angle);
};
</script>
obj.getValue(event or angle)
When you click on the chart this method can be used to get the corresponding value. The value is based on the minimum and maximum values. Example usage is:
<script>
seg = new RGraph.SVG.Segmented({
id: 'chart-container',
min: 0,
max: 100,
value: 63,
options: {
width: 60,
labelsCenterDecimals: 1
}
}).draw();
seg.container.onclick = function (e)
{
var value = seg.getValue(e);
// var value = seg.getValue(angle); // You can also pass the function an angle too
alert(value);
};
</script>
obj.getRadius(event)
When you click on the chart this method can be used to get the corresponding radius of the click starting from the center of the chart. Example usage is:
<script> seg = new RGraph.SVG.Segmented({ id: 'chart-container', min: 0, max: 100, value: 63, options: { width: 60, labelsCenterDecimals: 1 } }).draw(); seg.container.onclick = function (e) { var radius = seg.getRadius(e); alert(radius); }; </script>
Events
RGraph supports custom events that allow you to easily add interactivity to your charts if required. The following events are available:
beforedraw
This event fires at the start of thedraw
method before anything has been done.draw
This event fires at the end of thedraw
function.firstdraw
This event fires at the end of thedraw
function - but only the first time and so it fires only once after the firstdraw
call.adjustbegin
This event fires at the start of the adjusting process.adjust
This event fires (repeatedly) during the adjusting process.adjustend
This event fires at the end of the adjusting process.
new RGraph.SVG.Segmented({ id: 'chart-container', min: 0, max: 100, value: 35, options: { adjustable: true } }).draw().on('adjustbegin', function (obj) { console.log('Adjusting has started'); }).on('adjust', function (obj) { console.log('Adjusting is in progress...'); }).on('adjustend', function (obj) { alert('Adjusting has finished. New value is: ' + obj.value); });
Effects
These effects are available and can be used instead of thedraw
function.
- The
grow
effect (demo available in the download archive) - The
roundrobin
effect (demo available in the download archive)
<script> // // Optional callback function that's called when the effect is complete // function myCallback (obj) { // ... } new RGraph.SVG.Segmented({ id: 'chart-container', min: 0, max: 100, value: 63, options: { width: 60, labelsCenterDecimals: 1 } }).grow({frames: 60, callback: myCallback}); </script>