Share: Bookmark with delicious tweet this site Post to Facebook

RGraph: HTML5 canvas graph library - The RGraph.SetConfig() function

A graph showing RGraph.SetConfig()
[No canvas support]

Instead of using a number of .Set() calls, you may find that using the RGraph.SetConfig() method more to your tastes. The method is an alternative to setting the configuration of your graph. It can also facilitate reuse better, so that the appearance of your websites charts is the same. There's an example of its use below:


<script>
    window.onload = function ()
    {
        /**
        * This configuration could be stored in a central configuration file, making its reuse easier. You could also have
        * several different configurations that you pick and choose from depending on the requirements. Values in
        * subsequent calls to .SetConfig() will overwrite previous ones.
        */
        var config = {
                      'chart.colors':                  ['red', 'green'],
                      'chart.labels':                  ['John','Fred','June','Charles','Lou', 'Olga'],
                      'chart.title.yaxis':             'Amount',
                      'chart.title.yaxis.pos':         -0.2,
                      'chart.title.xaxis':             'Person',
                      'chart.background.grid.autofit': true
                     }
        var bar = new RGraph.Bar('cvs', [48,56,52,49,43,51]);
        RGraph.SetConfig(bar, config);
        bar.context.translate(20,-20);
        bar.Draw();
    }
</script>