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.


16th June, Rachel
I have a question about the 3D Bar chart
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?


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 »

How do I reference an RGraph object that was loaded with jQuery?


Posted by Joachim at 16:37 on Wednesday 30th August 2023 [link]
hi,
I'm creating RGRaph a charts using jQuery - e.g.

<script>jQuery(document).ready(function() {
var chartcvs = new RGraph.Scatter( {"chart_type":"...});
</script>

If I then try to access chart object e.g. with: "chartcvs.clearLassoState();"

It will fail with: "Uncaught ReferenceError: chartcvs is not defined"

Can you help with this?

Posted by Richard at 18:20 on Wednesday 30th August 2023 [link]
Because the Scatter chart object is created inside a function along with the var keyword the chartcvs variable is local to that function.

To access it outside of the jQuery.ready() function you would need to omit the var keyword. That then makes the chartcvs variable global. So you could access it by name.

For example:

<script>
    jQuery(document).ready(function()
    {
        // A global variable on purpose!
        myChart = new RGraph.Scatter({ ... });
    });

    myChart.draw();
</script>

There are other ways, like going via the RGraph registry to get to the chart object - but they're a little convoluted.

One thing you could do to make things clearer is use a GLOBALS object like this:

<script>
    GLOBALS = {};

    jQuery(document).ready(function()
    {
        GLOBALS.myChart = new RGraph.Scatter({
            // ...
        });
    });

    // You can then access the chart object by doing this:
    GLOBALS.myChart.draw();
</script>

Posted by Joachim at 09:59 on Thursday 31st August 2023 [link]
hi,

of course! Shame on me, I should have known.

[Replies are closed]