Removing 0 values from stacked 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 a13 on 18th March 2014
This source code:
===========================================================================
window.onload = function ()
         {
             var data = [[5,1,0,0,0],[4,3,0,1,0],[2,1,0,1,0],[0,1,0,2,0],[2,1,0,5,0],[4,2,0,0,0],[0,0,0,0,0],[2,0,1,4,0]];
             var hbar = new RGraph.HBar('cvs', data2)
                 .Set('labels', ['B', 'F', 'C', 'E', 'F', 'B', 'C', 'D'])
                 .Set('key', ['In-situ','Certification Process','Awaiting Sign Off', 'Awaiting RBI', 'Awaiting Peer Review'])
                
                 .Set('tooltips.event', 'onmousemove')
                 .Set('key.interactive', true)
                 .Set('colors', ['#CC0066', '#99CCFF', '#FF9933', '#FF3333', '#66CC33'])
                 .Set('grouping', 'stacked')
                 .Set('background.grid', true)
                 .Set('background.grid.hlines', false)
                 .Set('gutter.top', 75)
                 .Set('gutter.left', 100)
                 .Set('chart.key.position.graph.boxed',false)
                 .Set('chart.xlabels.offset',5)
                 .Set('axis.color', '#ccc')
                 hbar.Set('key.position', 'gutter')
                 .Set('key.position.y', 40)
                 .ondraw = function (obj)
                 {
                     for (var i=0; i<obj.coords.length; ++i) {
                         obj.context.fillStyle = '#fff';
                         RGraph.Text(obj.context, 'Verdana', 8, 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);
                     }
                 }
                 hbar.Draw();
             }
=====================================================================
will generate this graph

ulozto.net/xk6u4HP3/untitled-png

How can I remove 0 values from graph because at the moment Look at F values [2,1,0,5,0] and 2 zeros are placed on graph another example is for D bar values [2,0,1,4,0] there are two 0 values? any ideas?
Posted by Richard on 18th March 2014
Hi there,


Simply check to see if the value is not equal to 0:

if (obj.data_arr[i] != 0) {
}

And if it is don't add the text.



Richard
www.rgraph.net
If RGraph has helped you - please share the website - thanks!
Posted by Raissam on 18th March 2014
Sorry for duplicate question, but i dont see this threat..


works perfect..!! tks..

I was using this IF condition.. but in the wrong way...

if (obj.data_arr[i] <> 0)

Add a reply

 




« Back to message list
RGraph on social media