I'm trying to create a dynamic Bar chart with a line

« 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 Schultz on 23rd July 2013

I'm trying to create a dynamic bar graph inside my canvas. I currently already have a dynamic line chart working and a static bar graph working. The code I am using for the bar graph is

     dynamicBarPercent = new RGraph.Bar(id, averageNumber);
     dynamicBarPercent.Set('colors', GColours);
     dynamicBarPercent.Set('numyticks', 6);
     dynamicBarPercent.Set('background.grid.autofit.numhlines', 3);
     dynamicBarPercent.Set('background.grid.vlines', true);
     dynamicBarPercent.Set('background.grid.border', true);
     dynamicBarPercent.Set('hmargin', 5);
     dynamicBarPercent.Set('chart.gutter.left', 40);
     dynamicBarPercent.Set('chart.gutter.right', 600);
     dynamicBarPercent.Set('chart.gutter.bottom', 500);
     dynamicBarPercent.Set('chart.gutter.top', 60);
     dynamicBarPercent.Set('chart.title', 'Percantage of Bandwidth used');

I am getting the data into the averageNumber array by


The jsonData is a random integer, and the servlet which is generating the random integer is being called by an AJAX post request.

For some reason the bar graph is displaying 0 0 1 1 along the y-axis, and no data is being plotted. It is probably a very small error I am making, but I cannot figure it out.

Thank you for all the help!


Posted by RGraph support on 23rd July 2013
Hi there,

Try replacing your averageNumber array with a static array first:

dynamicBarPercent = new RGraph.Bar(id, [4,8,6,3,2,5,4]);

And then if that then works then your array probably isn't what you think it is - and you can look at it with either the browsers console or the RGraph p() function (which uses the alert() function):


The scale issue can be resolved by adding decimals to your numbers:

dynamicBarPercent.Set('chart.scale.decimals', 1);

Richard, RGraph support

Add a reply

« Back to message list