Search code examples
rgraph

How to set Bar width In Rgraph?


I am not able to set bars width if there is only 1 or 2 bars in chart. I am using Rgraph in my angular 7 app. I am unable to set marginInner property value based on the number of bars. Is there any property to set the barwidth directly. enter image description here


Solution

  • There's no property to set the width directly, but what you can do is put the logic for calculating the marginInner in the draw event or an exec() function. Here's an exec function example:

    new RGraph.Bar({
        id: 'cvs',
        data: [8,4,6,3,5,1,5],
        options: {
        }
    }).draw().exec(function (obj)
    {
        // Calculate marginInner here,set it and call RGraph.redraw();
    });
    

    This means that it runs only once after the chart has been drawn so you can then access the data (with obj.data) and then calculate how big the margin should be.