SVG Pie charts API reference

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

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.null
titleYThe specific Y coordinate of the title.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.null
titleSubtitleYThe specific Y coordinate of the subtitle.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

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>
Share RGraph!