SVG Pie charts API reference

Share RGraph:   Share or Like RGraph on Facebook!

Summary
Documentation about the SVG Pie chart including information on all the options and methods that are available to you.

 

Example

The code below produces a chart like this:

<script>
    // Some data that is to be shown on the Pie chart. For multiple
    lines it can also be an array of arrays
    var data = [280,45,133,152,278,221,56];

    new RGraph.SVG.Pie({
        id: 'chart-container',
        data: data,
        options: {
            labels: ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'],
            shadow: true,
            strokestyle: 'white',
            linewidth: 5
        }
    }).draw();
</script>

 

Properties

You can use these properties to control how the chart apears. You can set them by including them in the options section of the configuration as above.

Layout style:     
  

Chart configuration

PropertyDescriptionDefault
centerxIf required, you can position the Pie chart using this instead of the gutters.null
centeryIf required, you can position the Pie chart using this instead of the gutters.null
radiusIf required, you can size the Pie chart using this instead of the gutters.null

Margins

PropertyDescriptionDefault
gutterLeftThe left gutter of the chart, (the gutter is where the labels and title are)).35
gutterRightThe right gutter of the chart, (the gutter is where the labels and title are).35
gutterTopThe top gutter of the chart, (the gutter is where the labels and title are).35
gutterBottomThe bottom gutter of the chart, (the gutter is where the labels and title are).35

Colors

PropertyDescriptionDefault
colorsColors to be used for the pie segments.['#f66', '#6f6', '#66f', '#ff6', '#6ff', '#ccc', 'pink', 'orange', 'cyan', 'maroon', 'olive', 'teal']
strokestyleThe color of the seperating lines.rgba(0,0,0,0)

Labels and text

PropertyDescriptionDefault
textSizeThe size of the text.12
textFontThe font used to render the text.sans-serif
textColorThe color of the labels.black
textItalicWhether the labels are italic or not.false
textBoldWhether the labels are bold or not.false
labelsAn array of labels for the chart.[]
labelsSticksIf true this will cause the labels to be laid out with more spacing.true
labelsIngraphWhether the ingraph labels are displayed. By default these are placed in the center of the segment. If you have small/narrow segments the labels will probably not fit.false
labelsIngraphHalignThe horizontal alignment of the labels.center
labelsIngraphValignThe vertical alignment of the labels.center
labelsIngraphFontThe font family used to render the text. This falls back to the textFont setting if not specified.null
labelsIngraphSizeThe font size (in points) used to render the text. This falls back to the textSize setting if not specified.null
labelsIngraphItalicWhether the text is italic or not. This falls back to the textItalic setting if not specified.null
labelsIngraphBoldWhether the text is bold or not. This falls back to the textBold setting if not specified.null
labelsIngraphColorThe color used to render the text. This falls back to the textColor setting if not specified.null
labelsIngraphRadiusPosThis number is multiplied with the radius to get the radial distance that the text is placed at. The default, 0.5, will therefore put the text in the center of the segment.0.5
labelsIngraphSpecificIf you want to specify your own labels, you can with this property. Null values are just skipped.null
labelsIngraphUnitsPreUnits that are PREPENDED to the number.[an empty string]
labelsIngraphUnitsPostUnits that are APPENDED to the number.[an empty string]
labelsIngraphPointThe decimal point character. This can be multiple characters if required..
labelsIngraphThousandThe thousand seperator character. This can be multiple characters if required.,
labelsIngraphBackgroundThe background color of the labels.null
labelsIngraphFormatterThis can be a function that is passed an object that consists of two properties - object and number. It should return the fully formatted number.null
labelsIngraphDecimalsThis can be used to specify how many decimal places are displayed in the formatted labels.0

Shadow

PropertyDescriptionDefault
shadowWhether or not the chart has a shadow or not.false
shadowOffsetxThe X offset of the shadow.2
shadowOffsetyThe Y offset of the shadow.2
shadowBlurThe blurring of the shadow.2
shadowOpacityThe opacity of the shadow colour.0.25

Title

PropertyDescriptionDefault
titleThe title of the chart.(An empty string)
titleXThe specific X coordinate of the title. This can also be a string that looks like this: "+10" or "-10" in which case it's added to the calculated position.null
titleYThe specific Y coordinate of the title. This can also be a string that looks like this: "+10" or "-10" in which case it's added to the calculated position.null
titleHalignThe horizontal alignment of the title.center
titleValignThe vertical alignment of the title.bottom
titleColorThe color of the title. It defaults to be the same as the textColor property.null
titleFontThe font used to render the title.null
titleSizeThe size of the font used to render the title. It defaults to be a little larger than the textSize propertynull
titleBoldWhether the title is bold or not.false
titleItalicWhether the title is italic or not.false
titleSubtitleThe subtitle of the chart. If a subtitle is specified the title is moved up to accommodate it. As such you might need to give a larger gutterTop value.(An empty string)
titleSubtitleXThe specific X coordinate of the subtitle. This can also be a string that looks like this: "+10" or "-10" in which case it's added to the calculated position.null
titleSubtitleYThe specific Y coordinate of the subtitle. This can also be a string that looks like this: "+10" or "-10" in which case it's added to the calculated position.null
titleSubtitleHalignThe horizontal alignment of the subtitle.center
titleSubtitleValignThe vertical alignment of the subtitle.top
titleSubtitleColorThe color of the subtitle.#aaa
titleSubtitleFontThe font used to render the subtitle.null
titleSubtitleSizeThe size of the font used to render the subtitle. It defaults to be the same as the textSize setting.null
titleBoldWhether the subtitle is bold or not.false
titleSubtitleItalicWhether the subtitle is italic or not.false

Key

PropertyDescriptionDefault
keyAn array of the labels that appear on the key.null
keyColorsAn array of colors to be shown on the key. If not specified then the colors option will be used instead.null
keyTextBoldWhether the key text is bold or not.false
keyTextFontThe font to use for the key text. If not specified it defaults to the textFont setting.null
keyTextSizeThe size to use for the key text. If not specified then the textSize is used.null
ketTextItalicWhether the key text is italic or not.false
keyTextOffsetxThe horizontal pixel offset of the key text (just the text).0
keyTextOffsetyThe vertical pixel offset of the key text (just the text).-1
keyOffsetxThe horizontal pixel offset of the entire key.0
keyOffsetyThe horizontal pixel offset of the entire key.0
keyColorShapeThis controls which shape should be displayed on the key. It can be a string or an array of strings. The possible options are: rect, circle, triangle, line, dotrect

Tooltips

PropertyDescriptionDefault
tooltipsAn array of tooltips for the chart. This array should NOT be multidimensional - even for stacked or grouped charts.null
tooltipsOverrideIf required, this can be a function that totally handles the tooltip showing instead of the default RGraph tooltips. It should look like this:
tooltipsOverride: function (obj, opt)
{
    // Show tooltip
}
The opt is an argument that contains these items:
  • object The chart object.
  • index The index of the element (that triggered the tooltip).
  • sequentialIndex The sequential index of the element that was clicked.
  • text The text to be used as the tooltip. Remember that this may contain HTML (or whatever else you may have specified).
  • event The event object (either a click or mousemove event).
null
tooltipsCssClassThe CSS class thats applied to the tooltip DIV.RGraph_tooltip
tooltipsEventThe event used for tooltips (either click or mousemove.click

Highlight

PropertyDescriptionDefault
highlightStrokeThe color of the stroke of the highlight.rgba(0,0,0,0)
highlightFillThe color of the fill of the highlight.rgba(255,255,255,0.7)
highlightLinewidthThe linewidth of the stroke of the highlight.1

Other

PropertyDescriptionDefault
linewidthThe linewidth of the seperating lines.1
explodedThis can either be a number or an array and controls by how much the segments are exploded.0

Methods

 

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 onbeforedraw or ondraw) to the chart object.

 

obj.exec(func)

This function simply executes the function that you give it (there and then - not on any particular event)

 

Animation Effects

These effects are available and can be used instead of the .draw() function.
<script>
    /**
    * Optional callback function that's called when the effect is complete
    */
    function myCallback (obj)
    {
        // ...
    }

    var obj = new RGraph.SVG.Pie({
        id: 'mySVG',
        data: [3,4,7,5,6,9,8],
        options: {
        }
    }).roundRobin({frames: 60}, myCallback);
</script>