A question regarding the Bar chart with dynamic data arrays for plotting, labels and tooltips

« 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 AJ on 22nd January 2014
I am building javascript arrays for setting label, tooltips and bar data on the bar charts.

Sample code

var sampleData = new Array();
var barLabels = new Array();
var barTooltips = new Array();

for (var i = 0; i <= graphData.length; i++) {
     var currentObject = graphData[i];
     if (typeof(currentObject) != 'undefined') {
         barTooltips.push("Testing Stuff, {0}: {1}".format(currentObject.Quarter, currentObject.CashProduct));

var bar = new RGraph.Bar(canvasName, [sampleData])
     //.Set('gutter.top', 5)
     .Set('gutter.left', 50)
     .Set('gutter.right', 15)
     .Set('background.grid.vlines', false)
     .Set('background.grid.border', false)
     .Set('colors', [colorCode, colorCode])
     .Set('tooltips.event', 'mousemove')
     .Set('tooltips', [barTooltips])
     .Set('labels', [barLabels])
     //.Set('labels', [graphData[0].Quarter, graphData[1].Quarter])
     .Set('highlight.stroke', 'rgba(0,0,0,0.1)')
     .Set('strokestyle', 'rgba(0,0,0,0)')
     .Set('noaxes', true)
     .Set('ylabels', false)
     .Set('ymax', maxValueYAxis)
     .Set('labels.above', true)
     .Set('linewidth', 2)
     .Set('hmargin', 15)

if (!String.prototype.format) {
     String.prototype.format = function () {
         var args = arguments;
         return this.replace(/{(\d+)}/g, function (match, number) {
             return typeof args[number] != 'undefined' ? args[number] : match;

This result in graph where there is no spacing between bars(two in my case) and the labels for bars are together with comma between them, moreover the label rests between the two bars on x axis instead of being separate and below individual bars.

Posted by AJ on 22nd January 2014
Please ignore my question it was just a matter of removing square brackets from the array

      .Set('tooltips', [barTooltips])

Changed to

      .Set('tooltips', barTooltips) ----> Works

Add a reply

« Back to message list