MENU
.net Powerful JavaScript charts
About
RGraph is a JavaScript charts library based on HTML5 SVG and canvas. RGraph is mature (over 18 years old) and has a wealth of features making it an ideal choice to use for showing charts on your website.

More »

 

Version 7.20
Version 7.20 (released in June 2026) is the latest version of RGraph and the major change in this version is an update to the default values of properties making for better looking charts without having to set any properties. Read more about this and other changes in the changelog.

Download »

 

Download
Get the latest version of RGraph (version 7.20, 9th June 2026) from the download page. You can read the changelog here. There's also older versions available, minified files and links to cdnjs.com hosted libraries.

Download »

 

Latest forum posts
These are the latest support forum posts that have been posted or updated.


12th June, Marco
Should I use SVG or canvas for the charts on my website?
9th June, Richard
New version of RGraph: version 7.20
3rd June, Patrick
Question about installing RGraph
1st June, Ouja
How do I add a click event to a bar in my Bar chart?
8th May, Anthony Kuma
Does the SVG Line chart have outofbounds functionality?


Support forum »

 

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

More »

Using formatted labels

Introduction

Formatted labels are available to you as of version 6.0 of RGraph for both canvas and SVG charts and allow you to specify a single template string as the label which has certain macros in it and RGraph will replace those macros with the correct values.

Label templates are very similar to tooltip templates in their appearance albeit with fewer macros available to them (because only strings are permitted - not HTML).

Here's an example of a chart that uses label templates. In the download archive there's a demo called demos/activity-radial2.html which shows off label templates to good effect. It's not by any means a complicated demo - but it's effective.

Example

<script>
    data   = [28,19,39,45];
    values = RGraph.clone(data);
    labels = ['John','Fred','Mark','Andy'];

    new RGraph.Activity({
        id: 'cvs',
        min: 0,
        max: 100,
        value: data,
        options: {
            marginInner: 2,
            backgroundColor: 'transparent',
            backgroundGrid: false,
            backgroundGridRadials: false,
            backgroundRings: false,
            colors: ['red','blue','#aaa','black'],
            labels: '%{global:labels[%{index}]} (%{value_formatted})',
            labelsFormattedUnitsPost: '%',
            labelsSize: 10,
            labelsBold: true,
            labelsItalic: true,
            labelsColor: '#333',
            labelsOffsetx: -20,
            labelsFormattedUnitsPost:'%',
            responsive: [
                {maxWidth: null, css: {cssFloat: 'right'}},
                {maxWidth: 600, css: {cssFloat: 'none'}}
            ]
        }
    }).draw();
</script>

What macros are available?

You can use these macros when you're creating your template label string. Note that because there's no concept of a group or sequential index there's only one index macro available.
Name: %{index}
Description: 
This is the index of the label. Remember that counting starts at zero just like an array in javascript.
Name: %{property:title} or %{property:names[%{index}]}
Description: 
This macro allows you to reference your object properties from the template string. This means that you can set arbitrary properties (eg the names property as shown above) and reference them from your template string (similarly to the example chart shown above).
Name: %{value} %{value_formatted}
Description: 
These two properties allow you to show the value in your labels. The formatted value uses other properties that allow you to control the styling of the resulting number - these are shown below. The xxx in the property names should be replaced with the correct prefix for your chosen labels - so you'll need to check the correct api documentation [canvas] [SVG] page for your chosen chart type.
  • xxxFormattedPoint [.]: This character is used as the decimal point.
  • xxxFormattedThousand [,]: This character is used as the thousand separator.
  • xxxFormattedDecimals [0]: This specifies the number of decimals that are shown.
  • xxxFormattedUnitsPre [an empty string]: These units are prepended to the number.
  • xxxFormattedUnitsPost [an empty string]: These units are appended to the number.
Name: %{global:myVariable} %{global:myVariable[%{index}]}
Description: 
This macro allows you to reference global variables from the template string. This might be easier for you than setting your data as properties on the chart object.
Name: %{function:myFunction()} %{function:myFunction(%{index})}
Description: 
This macro allows you to call a function. The return value is used as the text that you will see in the label. Note that you can call your function without passing any arguments and you can also pass in the index as an argument.