Bar chart - how to not show 0 values?

Share RGraph:   Share or Like RGraph on Facebook!

« 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 Chris on 18th March 2013
Hi there,

Can you please tell me how to remove the zeros that display in the stacked bar charts?

example:
var line = new RGraph.Line('new_tix_trend',[52,43,38,76,72,69,22],[34,20,15,17,23,12,7],[0,1,0,1,1,1,5]);


the 3rd set has zeros in it. The stacked bar chart shows 0's stacked on each other. I simply want positive numbers to show.

Thanks in advance!!
~Chris
Posted by RGraph support on 18th March 2013
Hi there,

Simply loop through your data before giving to RGraph. A for loop will do the trick.


Richard, RGraph Support
Posted by Chris on 18th March 2013
Hi there,

Thanks for the quick reply. I need to pass the 0's or the offset will be wrong for the teams. Here is the code:

function New_Ticket_Graph()
{
  var bar = new RGraph.Bar('new_tick', [[2,1,0],[3,0,1],[1,0,0],[4,2,0],[0,1,0],[0,0,0],[0,0,0],[0,0,0]]);
  bar.Set('grouping', 'stacked');
  bar.Set('labels', ['03/11/13','03/12/13','03/13/13','03/14/13','03/15/13','03/16/13','03/17/13','03/18/13']);
  bar.Set('labels.above', true);
  bar.Set('labels.above.numbers', 2);
  bar.Set('linewidth', 2);
  bar.Set('strokestyle', 'white');
  bar.Set('colors', ['Gradient(#4572A7:#66f)','Gradient(#AA4643:white)','Gradient(#89A54E:white)']);
  bar.Set('shadow', true);
  bar.Set('shadow.offsetx', 1);
  bar.Set('shadow.offsety', 1);
  bar.Set('shadow.blue', 5);
  bar.Set('hmargin', 25);
  bar.Set('gutter.left', 45);
  bar.Set('background.grid.vlines', false);
  bar.Set('background.grid.border', false);
  bar.Set('axis.color', '#ccc');
  bar.Set('noyaxis', true);
  bar.Set('key', ['Team1','Team2','Team3']);
  bar.Set('key.position', 'gutter');
  bar.Set('key.position.x', bar.canvas.width - 650);
  bar.Set('key.position.y', 20);
  bar.Set('key.colors', ['blue','#c00','#0c0']);
  bar.ondraw = function (obj)
  {
   for (var i=0; i<obj.coords.length; ++i) {
    obj.context.fillStyle = 'white';
    RGraph.Text(obj.context, 'Verdana', 10, obj.coords[i][0] + (obj.coords[i][2] / 2), obj.coords[i][1] + (obj.coords[i][3] / 2),obj.data_arr[i].toString(),'center', 'center', null,null,null,true);
   }
  }
  bar.Draw();
}
</script>
Posted by RGraph support on 18th March 2013
Hi there,

If you mean that zeros are showing in chart.labels.above in the stacked chart then this may be something fixed in the beta.


Richard
Posted by Arthur on 28th April 2013
i have several pie charts, by using for loop and if condition to loop out the zero/null values...however, the labels still appear even though its not supposed to..

here is the portion of my script:
for(var i=0;i<jsonData.lvl3process_value.length;i++)
   if (jsonData.lvl3process_value[i] != 0.00)
   {
     pielvl3P.Get('chart.tooltips')[i]=jsonData.lvl3process_name[i] + '\\n' + jsonData.lvl3process_value[i].toFixed(2)+ '%';
   }
}

by right, the labels wont show at all, but it is still showing out, without value...
Posted by RGraph support on 29th April 2013
Hi there,

It's easy enough to go through your data and if a data point is zero or null then get rid of the associated label.

Richard
Posted by a13 on 17th March 2014
is this fixed yet?

got the same problem
Posted by Richard on 17th March 2014
Hi there,

You'll have to detail your issue (in a new thread). Given that this is a year old - probably not.




Richard
Posted by Chris on 21st March 2014
Hi there,

Thanks for the quick reply. I need to pass the 0's or the offset will be wrong for the teams. Here is the code:

function New_Ticket_Graph()
{
   var bar = new RGraph.Bar('new_tick', [[2,1,0],[3,0,1],[1,0,0],[4,2,0],[0,1,0],[0,0,0],[0,0,0],[0,0,0]]);
   bar.Set('grouping', 'stacked');
   bar.Set('labels', ['03/11/13','03/12/13','03/13/13','03/14/13','03/15/13','03/16/13','03/17/13','03/18/13']);
   bar.Set('labels.above', true);
   bar.Set('labels.above.numbers', 2);
   bar.Set('linewidth', 2);
   bar.Set('strokestyle', 'white');
   bar.Set('colors', ['Gradient(#4572A7:#66f)','Gradient(#AA4643:white)','Gradient(#89A54E:white)']);
   bar.Set('shadow', true);
   bar.Set('shadow.offsetx', 1);
   bar.Set('shadow.offsety', 1);
   bar.Set('shadow.blue', 5);
   bar.Set('hmargin', 25);
   bar.Set('gutter.left', 45);
   bar.Set('background.grid.vlines', false);
   bar.Set('background.grid.border', false);
   bar.Set('axis.color', '#ccc');
   bar.Set('noyaxis', true);
   bar.Set('key', ['Team1','Team2','Team3']);
   bar.Set('key.position', 'gutter');
   bar.Set('key.position.x', bar.canvas.width - 650);
   bar.Set('key.position.y', 20);
   bar.Set('key.colors', ['blue','#c00','#0c0']);
   bar.ondraw = function (obj)
   {
     for (var i=0; i<obj.coords.length; ++i) {
      obj.context.fillStyle = 'white';
      RGraph.Text(obj.context, 'Verdana', 10, obj.coords[i][0] + (obj.coords[i][2] / 2), obj.coords[i][1] + (obj.coords[i][3] / 2),obj.data_arr[i].toString(),'center', 'center', null,null,null,true);
     }
   }
   bar.Draw();
}
</script>
Posted by Richard on 21st March 2014
Hi there,

I don't know what you're asking - please detail your issue in full in a NEW thread - ideally with a URL to an example.

Richard
Posted by Stu Andrews on 15th March 2017
Hi Richard,

Just searching through the site, have got a similar (maybe the same) query as the above.

With a simple bar graph, jsfiddle.net/jw19m3kL/1/, that has the labels.above value set to true, the zero values display.

I can't remove the 0 in the data string, that gives back problems (and I don't want to remove it from the data string, is valuable data), but I'd love to be able to option on/off that zeros do not display in the data labels that show.

Any way to do that currently?

Cheers!
Posted by Richard on 15th March 2017
Hi there,

You can do that if you use the labelsAboveSpecific option and specify all of the labels yourself.

This option allows to specify exactly what the label should be - so just leave the one that you don't want as blank.





Richard
Posted by Stu Andrews on 16th March 2017
Thanks Richard!

Add a reply




« Back to message list