About
RGraph is a JavaScript charts library based on HTML5 SVG and canvas. RGraph is mature (over 15 years old) and has a wealth of features making it an ideal choice to show charts on your website.

More »

 

License
RGraph can be used for free under the GPL or if that doesn't suit your situation there's an inexpensive (£99) commercial license available.

More »

 

Download
Get the latest version of RGraph (version 6.17) from the download page. There's also older versions available, minified files and links to cdnjs.com hosted libraries.

More »

Semi-circular Progress bar API reference

Example

<script>
    scp = new RGraph.SVG.SemiCircularProgress({
        id: 'chart-container',
        min: 0,
        max: 200,
        value: [50,30,60],
        options: {
            colors: ['rgba(0,255,0,0.25)',
                'rgba(255,0,0,0.25)',
                'rgba(255,255,0,0.25)'
            ],
            marginRight: 75,
            marginLeft: 75,
            marginTop: 50,
            scale: true,
            backgroundColor: '#E8FAE8',
            backgroundColorOpacity: 1,
            backgroundGrid: true,
            scaleLabelsSize: 10,
            scaleLabelsCount: 20,
            scaleUnitsPost: '%',
            backgroundGridRadialsCount: 20,
            labelsCenterUnitsPost: '%',
            labelsCenterDecimals: 1,
            tooltips: 'Amount: %{value_formatted} boxes',
            tooltipsCss: {
                fontSize: '20pt',
                fontWeight: 'bold'
            }
        }
    }).draw();
</script>

The obj.coords property

The obj.coords array is new for version 6.05 and provides an alternative to the obj.nodes properties - being more like the canvas way of storing coordinates to shapes. The object is an array of objects which each contain the details of the segments that are drawn on the chart. If you want to, you can replay these coordinates by using the RGraph api method RGraph.SVG.TRIG.getArcPath3 and then using the resulting path as the argument when you create a path node, like this:

// Create the outer arc path
var arcPath1 = RGraph.SVG.TRIG.getArcPath3({
    cx:     scp.coords[0].cx,
    cy:     scp.coords[0].cy,
    radius: scp.coords[0].radiusOuter,
    start:  scp.coords[0].start,
    end:    scp.coords[0].end,
    anticlockwise: false,
    lineto:false
});

// Crete the inner arc path
var arcPath2 = RGraph.SVG.TRIG.getArcPath3({
    cx:     scp.coords[0].cx,
    cy:     scp.coords[0].cy,
    radius: scp.coords[0].radiusInner,
    start:  scp.coords[0].end,
    end:    scp.coords[0].start,
    anticlockwise: true,
    lineto: true
});

// Now create an SVG path object out of the two paths created above
var path = scp.create('path', null, {
    d: '{1} {2} z'.format(arcPath1, arcPath2),
    stroke: 'black',
    fill: 'transparent'
});

The obj.nodes property

As well as coordinates, the Semi-circular Progress mmeter aintains references to the nodes that are created - such as the bar, the background and text nodes. For example:

You could, for example, add your own event listeners like this:

<script>
    obj.nodes.labelsCenter.onclick = function (e)
    {
        alert('The value is: ' + scp.value);
    }

    obj.nodes.labelsCenter.onmousemove = function (e)
    {
        e.target.style.cursor = 'pointer';
    }
</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

Name: centerx
Description: 
If required, you can position the Semi-circular Progress using this instead of the margins. As well as a number, that gives the exact coordinate of the center position of the meter, this can also be a string like this: centerx: '+25' or this: centerx: '-40' which is then used to adjust the calculated coordinate.
Default: null
Name: centery
Description: 
If required, you can position the Semi-circular Progress using this instead of the margins. As well as a number, that gives the exact coordinate of the center position of the meter, this can also be a string like this: centery: '+25' or this: centery: '-40' which is then used to adjust the calculated coordinate.
Default: null
Name: radius
Description: 
If required, you can size the Semi-circular Progress using this instead of the margins. As well as a number, that gives the exact size of the meter, this can also be a string like this: radius: '+25' or this: radius: '-40' which is then used to adjust the calculated coordinate.
Default: null
Name: width
Description: 
The width of the progress bar (ie the outer radius minus the inner radius).
Default: 60

Margin properties

Name: marginLeft
Description: 
The left margin of the chart, (the margin is where the labels and title are)).
Default: 35
Name: marginRight
Description: 
The right margin of the chart, (the margin is where the labels and title are).
Default: 35
Name: marginTop
Description: 
The top margin of the chart, (the margin is where the labels and title are).
Default: 35
Name: marginBottom
Description: 
The bottom margin of the chart, (the margin is where the labels and title are).
Default: 35

Background properties

Name: backgroundFill
Description: 
The color of the background fill.
Default: Gradient(white:#aaa)
Name: backgroundFillOpacity
Description: 
The opacity of the background fill color.
Default: 0.25
Name: backgroundGrid
Description: 
Whether the background grid is drawn or not.
Default: true
Name: backgroundGridLinewidth
Description: 
The linewidth of the background grid.
Default: 1
Name: backgroundGridColor
Description: 
The color of the background grid.
Default: #ddd
Name: backgroundGridRadials
Description: 
Whether the radial lines (the lines that emanate from the center coordinates) are drawn or not.
Default: true
Name: backgroundGridRadialsCount
Description: 
The number of radial lines that are drawn.
Default: 10
Name: backgroundGridCircles
Description: 
Whether the semi-circular border bar lines are drawn on the background grid.
Default: true
Name: backgroundGridMargin
Description: 
This is the distance that the background grid extends to.
Default: 20

Color properties

Name: colors
Description: 
The color to be used for the progress bar.
Default: [#6d6, #FFA5A5, #A0A2F8, yellow, gray, pink, orange, cyan, green]
Name: colorsStroke
Description: 
The color of the outline of the progress bar.
Default: transparent

Labels and text properties

Name: textFont
Description: 
The font used to render the text.
Default: Arial, Verdana, sans-serif
Name: textSize
Description: 
The size of the text.
Default: 12
Name: textColor
Description: 
The color of the labels.
Default: black
Name: textItalic
Description: 
Whether the labels are italic or not.
Default: false
Name: textBold
Description: 
Whether the labels are bold or not.
Default: false
Name: text
Description: 
This allows you to add custom text to your chart if you want to. There's a dedicated page that describes this option here.
Default: null
Name: labelsMin
Description: 
Whether to show the minimum label.
Default: true
Name: labelsMinFont
Description: 
The font used to render the minimum label.
Default: null
Name: labelsMinSize
Description: 
The size of the minimum label.
Default: null
Name: labelsMinColor
Description: 
The color of the minimum label.
Default: null
Name: labelsMinItalic
Description: 
Whether the minimum label is italic or not.
Default: null
Name: labelsMinBold
Description: 
Whether the minimum label is bold or not.
Default: null
Name: labelsMinUnitsPre
Description: 
Units that are pre-pended to the minimum label.
Default: null
Name: labelsMinUnitsPost
Description: 
Units that are appended to the minimum label.
Default: null
Name: labelsMinPoint
Description: 
The character that's used as the decimal point for the minimum label.
Default: null
Name: labelsMinThousand
Description: 
The character that's used as the thousand separator for the minimum label.
Default: null
Name: labelsMinDecimals
Description: 
The number of decimals to apply to the minimum label.
Default: null
Name: labelsMinSpecific
Description: 
The specific text to use as the minimum label.
Default: null
Name: labelsMinFormatter
Description: 
A function that's used as the formatter for the minimum label. This function should look like this:
labelsMinFormatter: function (obj, num)
{
}
Default: null
Name: labelsMax
Description: 
Whether to show the maximum label.
Default: true
Name: labelsMaxFont
Description: 
The font used to render the maximum label.
Default: null
Name: labelsMaxSize
Description: 
The size of the maximum label.
Default: null
Name: labelsMaxColor
Description: 
The color of the maximum label.
Default: null
Name: labelsMaxItalic
Description: 
Whether the maximum label is italic or not.
Default: null
Name: labelsMaxBold
Description: 
Whether the maximum label is bold or not.
Default: null
Name: labelsMaxUnitsPre
Description: 
Units that are pre-pended to the maximum label.
Default: null
Name: labelsMaxUnitsPost
Description: 
Units that are appended to the maximum label.
Default: null
Name: labelsMaxPoint
Description: 
The character that's used as the decimal point for the maximum label.
Default: null
Name: labelsMaxThousand
Description: 
The character that's used as the thousand separator for the maximum label.
Default: null
Name: labelsMaxDecimals
Description: 
The number of decimals to apply to the maximum label.
Default: null
Name: labelsMaxSpecific
Description: 
The specific text to use as the maximum label.
Default: null
Name: labelsMaxFormatter
Description: 
A function that's used as the formatter for the maximum label. This function should look like this:
labelsMaxFormatter: function (obj, num)
{
}
Default: null
Name: labelsCenter
Description: 
Whether to show the center label.
Default: true
Name: labelsCenterIndex
Description: 
If you're showing multiple values on your chart this is the index of the value in the data array that is used as the center label.
Default:  0
Name: labelsCenterFont
Description: 
The font used to render the center label.
Default: null
Name: labelsCenterSize
Description: 
The size of the center label.
Default: 40
Name: labelsCenterColor
Description: 
The color of the center label.
Default: null
Name: labelsCenterItalic
Description: 
Whether the center label is italic or not.
Default: null
Name: labelsCenterBold
Description: 
Whether the center label is bold or not.
Default: null
Name: labelsCenterUnitsPre
Description: 
Units that are pre-pended to the center label.
Default: null
Name: labelsCenterUnitsPost
Description: 
Units that are appended to the center label.
Default: null
Name: labelsCenterPoint
Description: 
The character that's used as the decimal point for the center label.
Default: null
Name: labelsCenterThousand
Description: 
The character that's used as the thousand separator for the center label.
Default: null
Name: labelsCenterDecimals
Description: 
The number of decimals to apply to the center label.
Default: null
Name: labelsCenterSpecific
Description: 
The specific text to use as the center label.
Default: null
Name: labelsCenterFormatter
Description: 
A function that's used as the formatter for the center label. This function should look like this:
labelsCenterFormatter: function (obj, num)
{
}
Default: null

Scale properties

Name: scale
Description: 
Whether a scale is shown on the chart. If yes the minimum and maximum value that you give to the constructor will be used by default.
Default: false
Name: scaleMin
Description: 
This is the minimum value for the scale. This just affects the scale on the chart - not the bar itself.
Default:  0
Name: scaleMax
Description: 
This is the maximum value for the scale. You don't have to give it and if you don't it will be the same as the max value that you give when you create the chart. This just affects the scale on the chart - not the bar that represents the value.
Default: null
Name: scaleLabelsCount
Description: 
This property allows you to stipulate how many labels there are on the scale.
Default: 10
Name: scaleLabelsColor
Description: 
The color of the labels (defaults to the textColor property).
Default: null
Name: scaleLabelsFont
Description: 
The font of the labels (defaults to the textFont property)
Default: null
Name: scaleLabelsSize
Description: 
The size of the labels (defaults to the textSize property)
Default: null
Name: scaleLabelsBold
Description: 
Whether the scale labels are bold or not (defaults to the textBold property)
Default: null
Name: scaleLabelsItalic
Description: 
Whether the scale labels are italic or not (defaults to the textItalic property)
Default: null
Name: scaleLabelsOffsetr
Description: 
If you want to offset the scale labels (radially) you can do that with this property.
Default:  0
Name: scaleLabelsOffsetx
Description: 
If you want to offset the scale labels (in the horizontal direction) you can do that with this property.
Default:  0
Name: scaleLabelsOffsety
Description: 
If you want to offset the scale labels (in the vertical direction) you can do that with this property.
Default:  0
Name: scaleUnitsPre
Description: 
These units are prepended to the scale numbers on the chart.
Default: A blank string
Name: scaleUnitsPost
Description: 
These units are appended to the scale numbers on the chart.
Default: A blank string
Name: scaleDecimals
Description: 
This stipulates how many decimal places are shown on the scale numbers on the chart.
Default:  0
Name: scalePoint
Description: 
The character that's used as the decimal point for the scale.
Default: .
Name: scaleThousand
Description: 
The character that's used as the thousand separator for the scale.
Default: ,
Name: scaleFormatter
Description: 
If you want to handle the formatting of the scale yourself you can do so with this property. It should be a function that returns the formatted number.
Default: null

Title properties

Name: title
Description: 
The title of the chart.
Default: (An empty string)
Name: titleX
Description: 
The specific x-axis 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.
Default: null
Name: titleY
Description: 
The specific y-axis 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.
Default: null
Name: titleOffsetx
Description: 
An offset value that is added to the calculated x-axis coordinate.
Default:  0
Name: titleOffsety
Description: 
An offset value that is added to the calculated y-axis coordinate.
Default:  0
Name: titleHalign
Description: 
The horizontal alignment of the title.
Default: center
Name: titleColor
Description: 
The color of the title. It defaults to be the same as the textColor property.
Default: null
Name: titleFont
Description: 
The font used to render the title.
Default: null
Name: titleSize
Description: 
The size of the font used to render the title. It defaults to be a little larger than the textSize property.
Default: null
Name: titleBold
Description: 
Whether the title is bold or not.
Default: null
Name: titleItalic
Description: 
Whether the title is italic or not.
Default: null
Name: titleSubtitle
Description: 
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 marginTop value.
Default: (An empty string)
Name: titleSubtitleColor
Description: 
The color of the subtitle.
Default: #aaa
Name: titleSubtitleFont
Description: 
The font used to render the subtitle.
Default: null
Name: titleSubtitleSize
Description: 
The size of the font used to render the subtitle.
Default: null
Name: titleSubtitleBold
Description: 
Whether the subtitle is bold or not.
Default: null
Name: titleSubtitleItalic
Description: 
Whether the subtitle is italic or not.
Default: null

Tooltip properties

Name: tooltips
Description: 
An array containing the single tooltip that the chart shows. You can also check the canvas tooltips documentation for more information.
Default: null
Name: tooltipsOverride
Description: 
This can be a function that 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).
Default: null
Name: tooltipsEvent
Description: 
The event used for tooltips (either click or mousemove.
Default: click
Name: tooltipsFormattedPoint
Description: 
When using formatted tooltip strings this is used as the point when using the %{value_formatted} option.
Default: .
Name: tooltipsFormattedThousand
Description: 
When using formatted tooltip strings this is used as the thousand separator when using the %{value_formatted} option.
Default: ,
Name: tooltipsFormattedDecimals
Description: 
When using formatted tooltip strings this specifies the number of decimals when using the %{value_formatted} option.
Default:  0
Name: tooltipsFormattedUnitsPre
Description: 
When using formatted tooltip strings these units are prepended to the number when using the %{value_formatted} option.
Default: (an empty string)
Name: tooltipsFormattedUnitsPost
Description: 
When using formatted tooltip strings these units are appended to the number when using the %{value_formatted} option.
Default: (an empty string)
Name: tooltipsFormattedKeyLabels
Description: 
The labels that are used in the formatted tooltip key.
Default: [] (an empty array)
Name: tooltipsFormattedKeyColors
Description: 
The colors that are used in the formatted tooltip key. Normally these are automatically taken from the colors on the chart but can be specified differently using this property.
Default: null
Name: tooltipsFormattedKeyColorsShape
Description: 
This is the shape that's used in the tooltip key. It can be square or circle
Default: square
Name: tooltipsFormattedKeyColorsCss
Description: 
By using this property you can add css values to the key color shape that appears in the tooltip key. Note the property name is "color" and not "colors" like previous properties. It should be an object of css properties like this:
tooltipsFormattedKeyColorsCss : {
    border: "1px solid #ddd";
}
Default: null
Name: tooltipsFormattedListType
Description: 
With this property you can switch between an unordered list (the default) and an ordered list. Possible values are ul and ol.
Default: ul
Name: tooltipsFormattedListItems
Description: 
This should be a two-dimension array of the list items that are to be shown for all of the tooltips. An example of this property is:
tooltipsFormattedListItems: [
    ['Bill','Jerry','Berty'], // First tooltip
    ['Gill','Carrie','Lucy'], // Second tooltip
    ['Pob','Nobby','Hilda']   // Third tooltip
]
You can use css to style this list - for example:
.RGraph_tooltip ul#rgraph_formatted_tooltips_list li {
    text-align: left;
    color: yellow;
}
Default: null
Name: tooltipsFormattedTableHeaders
Description: 
When showing a table in the tooltips this can be an array of headers for the table. These are added to the tooltip using th tags.
Default: null
Name: tooltipsFormattedTableData
Description: 
This is the data that is added to the table. This is a 3-dimensional array so it's easy to make a mistake. See the example in the canvas documentation, copy the code from it and then modify it suit. You'll create fewer bugs this way.
Default: null)
Name: tooltipsPointer
Description: 
By default the tooltips have a small triangular pointer that points to the shape that was clicked on. You can turn this off with this property.
Default: true
Name: tooltipsPointerCss
Description: 
If you want any css values applied to the tooltips pointer (a css border, for example) then specify an object containing those values to this property. For example:
tooltipsPointerCss: {
    borderLeft: 'gray 2px solid',
    borderBottom: 'gray 2px solid'
}
Default: null
Name: tooltipsPointerOffsetx
Description: 
This allows you to adjust the horizontal position of the tooltips pointer.
Default:  0
Name: tooltipsPointerOffsety
Description: 
This allows you to adjust the vertical position of the tooltips pointer.
Default:  0
Name: tooltipsPositionStatic
Description: 
The new default (as of August 2020) is for tooltips to be positioned statically and not be dependent on the mouse position. If you don't want this for whatever reason, you can disable it with this setting. When you set it to false tooltips are positioned next to the mouse pointer.
Default: true
Name: tooltipsCss
Description: 
If you want to specify some css that gets applied to all of the tooltips, but don't want to use the RGraph.SVG.tooltips.style object (which gets applied to all of the tooltips on the page for every chart) you can use this property to give some per-object css for the tooltips. These are css styles that get applied to all of the tooltips for the specific object only. It should look like this:
tooltipsCss: {
    fontFamily: 'Verdana',
    fontSize: '20pt'
}
Default: null
Name: tooltipsCssClass
Description: 
The css class that's applied to the tooltip div.
Default: RGraph_tooltip
Name: tooltipsOffsetx
Description: 
This property allows you to shift the tooltips left or right.
Default:  0
Name: tooltipsOffsety
Description: 
This property allows you to shift the tooltips up or down.
Default:  0

Highlight properties

Name: highlightStroke
Description: 
The color of the stroke of the highlight.
Default: rgba(0,0,0,0)
Name: highlightFill
Description: 
The color of the fill of the highlight.
Default: rgba(255,255,255,0.7)
Name: highlightLinewidth
Description: 
The linewidth of the stroke of the highlight.
Default: 1

Other properties

Name: linewidth
Description: 
The linewidth of the separating lines.
Default: 1
Name: adjustable
Description: 
This property, when set to true, allows the Semi-circular Progress bar to be dynamically adjusted. There are three events which are asscociated with adjusting:
  • adjustbegin
  • adjust
  • adjustend
The adjustbegin event fires when you first click on the indicator bar - much like the mousedown event. The adjust event fires during adjusting - much like the mousemove event. And the adjustend event fires when you finish adjusting - much like the mouseup event. There's a demo of an adjustable chart in the download archive called demos/svg-scp-adjustable.html
Default: false
Name: responsive
Description: 
This option is new to the July 2023 release (v6.13) and allows you to inline the responsive configuration instead of appending it on to the end of the object it as a function. The documentation and demo pages have been updated to use this new option. You can read more about the responsive feature by reading the responsive configuration page.
Default: null

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 RGraph.SVG.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.

Events

RGraph supports custom events that allow you to easily add interactivity to your charts if required. The following events are available:

For example:
new RGraph.SVG.SemiCircularProgress({
    id: 'chart-container',
    min: 0,
    max: 100,
    value:50,
    options: {
    }
}).on('tooltip', function (obj)
{
    console.log('The draw event has fired');
    
}).draw();

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)
    {
        // ...
    }

    new RGraph.SVG.SemiCircularProgress({
        id: 'chart-container',
        min: 0,
        max: 100,
        value: 84.99,
        options: {
            colors: ['Gradient(#faa:pink)'],
            labelsCenterUnitsPre: '$',
            labelsCenterDecimals: 2
        }
    }).grow({frames: 60, callback: myCallback});
</script>