SVG Pie charts API reference

  Read comments...

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

 

Example

<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>

The code above produces a chart like this:

 

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.

 

Chart configuration

centerx
If required, you can position the Pie chart using this instead of the gutters.
Default: null

centery
If required, you can position the Pie chart using this instead of the gutters.
Default: null

radius
If required, you can size the Pie chart using this instead of the gutters.
Default: null

 

Margins

gutterLeft
The left gutter of the chart, (the gutter is where the labels and title are)).
Default: 35

gutterRight
The right gutter of the chart, (the gutter is where the labels and title are).
Default: 35

gutterTop
The top gutter of the chart, (the gutter is where the labels and title are).
Default: 35

gutterBottom
The bottom gutter of the chart, (the gutter is where the labels and title are).
Default: 35

 

Colors

colors
Colors to be used for the pie segments.
Default: ['#f66', '#6f6', '#66f', '#ff6', '#6ff', '#ccc', 'pink', 'orange', 'cyan', 'maroon', 'olive', 'teal']

strokestyle
The color of the seperating lines.
Default: rgba(0,0,0,0)

 

Labels and text

textSize
The size of the text.
Default: 12

textFont
The font used to render the text.
Default: sans-serif

textColor
The color of the labels.
Default: black

textItalic
Whether the labels are italic or not.
Default: false

textBold
Whether the labels are bold or not.
Default: false

labels
An array of labels for the chart.
Default: []

 

Shadow

shadow
Whether or not the chart has a shadow or not.
Default: false

shadowOffsetx
The X offset of the shadow.
Default: 2

shadowOffsety
The Y offset of the shadow.
Default: 2

shadowBlur
The blurring of the shadow.
Default: 2

shadowOpacity
The opacity of the shadow colour.
Default: 0.25

 

Title

title
The title of the chart.
Default: (An empty string)

titleX
The specific X coordinate of the title.
Default: null

titleY
The specific Y coordinate of the title.
Default: null

titleHalign
The horizontal alignment of the title.
Default: center

titleValign
The vertical alignment of the title.
Default: bottom

titleColor
The color of the title. It defaults to be the same as the textColor property.
Default: null

titleFont
The font used to render the title.
Default: null

titleSize
The size of the font used to render the title. It defaults to be a little larger than the textSize property
Default: null

titleBold
Whether the title is bold or not.
Default: false

titleItalic
Whether the title is italic or not.
Default: false

titleSubtitle
The 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.
Default: (An empty string)

titleSubtitleX
The specific X coordinate of the subtitle.
Default: null

titleSubtitleY
The specific Y coordinate of the subtitle.
Default: null

titleSubtitleHalign
The horizontal alignment of the subtitle.
Default: center

titleSubtitleValign
The vertical alignment of the subtitle.
Default: top

titleSubtitleColor
The color of the subtitle.
Default: #aaa

titleSubtitleFont
The font used to render the subtitle.
Default: null

titleSubtitleSize
The size of the font used to render the subtitle. It defaults to be the same as the textSize setting.
Default: null

titleBold
Whether the subtitle is bold or not.
Default: false

titleSubtitleItalic
Whether the subtitle is italic or not.
Default: false

 

Tooltips

tooltips
An array of tooltips for the chart. This array should NOT be multidimensional - even for stacked or grouped charts.
Default: null

tooltipsOverride
If 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:
Default: null

tooltipsEffect
This can be fade or none and determines the effect used for tooltips.
Default: fade

tooltipsCssClass
The CSS class thats applied to the tooltip DIV.
Default: RGraph_tooltip

tooltipsEvent
The event used for tooltips (either click or mousemove.
Default: click

 

Highlight

highlightStroke
The color of the stroke of the highlight.
Default: rgba(0,0,0,0)

highlightFill
The color of the fill of the highlight.
Default: rgba(255,255,255,0.7)

highlightLinewidth
The linewidth of the stroke of the highlight.
Default: 1

 

Attribution

attribution
Whether to show the attribution link or not. If you're going to link to the RGraph website elsewhere on your site then set this to false.
Default: true

attributionX
The X coordinate of the link. This can be a number (in which case it's treated as the absolute coordinate) or it can be a string starting with a + or - (in which case it's treated as an adjustment to the default value).
Default: (bottom right corner of the SVG tag)

attributionY
The Y coordinate of the link. This can be a number (in which case it's treated as the absolute coordinate) or it can be a string starting with a + or - (in which case it's treated as an adjustment to the default value).
Default: (bottom right corner of the SVG tag)

attributionHref
The href of the link (ie the page to link to).
Default: http://www.rgraph.net/svg/index.html

attributionHalign
The horizontal alignment of the link.
Default: right

attributionValign
The vertical alignment of the link
Default: bottom

attributionFont
The font used to render the link.
Default: sans-serif

attributionSize
The point size of the link.
Default: 8

attributionColor
The color of the link.
Default: gray

attributionItalic
Whether the link is italic or not.
Default: false

attributionBold
Whether the link is bold or not.
Default: false

 

Other

linewidth
The linewidth of the seperating lines.
Default: 1

exploded
This can either be a number or an array and controls by how much the segments are exploded.
Default: 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...
X

Comments