Is it possible to fix the width of the bar in simple bar chart?


« Back to message list

Enter your email address to get email updates on this topic. You can stop receiving updates by clicking the link in the update email messages.

Posted by Pravallika on 27th December 2012
Hi,

    I have fixed canvas width to 946px. It consists maximum 6, and minimum 1 bar. If it consists 6 bars the width of each bar is less. If the number of bars decreases then the width of each bar increases. Is there any way to fix the width of the bar?

Thanks in advance
Posted by RGraph support on 27th December 2012
Hi,

The's no option for it but based on the number of bars and the desired width you can work it out:

(946 - (numbars * width)) / 2

That gives you the approx setting for each gutter (left and right).

And if you wanted you could add that as an onbeforedraw event.

PS If you could link to the RGraph website I'd appreciate it - thanks.

Richard, RGraph Support
Posted by Pravallika on 27th December 2012
Hi,

   But there is no desired width for each bar. Based on 'chart.hmargin', the width of the bar is changed. Can I use this option instead of width in the above formula
Posted by RGraph support on 27th December 2012
Hi,

No desired width? You said you wanted the width to remain constant. The chart.hmargin setting is the space either side of the bars.

PS If you could link to the RGraph website I'd appreciate it - thanks.

Richard, RGraph Support
Posted by Pravallika on 27th December 2012
Hi,

    There is no option to set the desired width. The width of each bar is calculated

based on canvas width and the number of bars. Please tell me how to set desired width

for a bar?

Thanks in advance
Posted by RGraph support on 27th December 2012
Hi,

There's no option to set the desired width for a bar. You'll need to work it out based on the width of the canvas, the gutter settings, the chart.hmargin setting and the number of bars.

PS If you could link to the RGraph website I'd appreciate it - thanks.

Richard, RGraph Support
Posted by Prashant Dikonda on 28th December 2012
Hi Pravallika,

If you have a fix no. of bars in chart,then you can fix the width as chart.
e.g You have max 6 bars,create empty array and push the item in it ..

var v = new Array();
  v = [3, 4, 6];

Users = [];//empty array
g.push(v);
var len = g.length;
for (var i = len; i < 6; i++) {
                         g.push("");
                     }

And after assign the g array to your graph.
Like
var bar = new RGraph.Bar('cvs', g);

From this you can set all 6 bars divided in your canvas size.
And then set your hmargin to bar graph .
And you can get fix width.

Thanks.

Posted by Prashant Dikonda on 28th December 2012
Hi Pravallika,

If you have a fix no. of bars in chart,then you can fix the width as chart.
e.g You have max 6 bars,create empty array and push the item in it ..

var v = new Array();
  v = [3, 4, 6];

Users = [];//empty array
g.push(v);
var len = g.length;
for (var i = len; i < 6; i++) {
                         g.push("");
                     }

And after assign the g array to your graph.
Like
var bar = new RGraph.Bar('cvs', g);

From this you can set all 6 bars divided in your canvas size.
And then set your hmargin to bar graph .
And you can get fix width.

Thanks.

Posted by RGraph support on 28th December 2012
Hi,

There's no option to fix the width of the bars.


PS If you could link to the RGraph website I'd appreciate it - thanks.

Richard, RGraph Support
Posted by Prashant Dikonda on 28th December 2012
Hi,

This is not for fix the width.

This is for same size of bars but fix no. of bars on canvas.

Thanks,
Prashant
Posted by RGraph support on 28th December 2012
Hi,

I don't know what you want. If you have only two data points then simply pad the data array with zero values.

PS If you could link to the RGraph website I'd appreciate it - thanks.

Richard, RGraph Support
Posted by pravallika on 3rd January 2013
Hi Prashant Dikonda,

     In my application the number of bars are not fixed. Some time I will get 3 and some other time I'l get 6. So these values are coming dynamically

Thanks

Add a reply

 




« Back to message list
RGraph on social media