4

I use Highchart to draw some charts. I use this format in tooltip of highchart:

tooltip: {
     crosshairs: [true, true],
     shared: true,
     useHTML: true,
    formatter: function() {

            var s = [];
            s.push('<table><tr><td style="text-align:right;" colspan="3"><b>' + 
             this.x + '</b></td></tr>');
            $.each(this.points, function(i, point) {
                s.push('<tr><td style="text-align: right;">'+
                              '<b><span style="color:'+point.series.color +'">\u25CF</span></b>'+
                           '</td>'+
                           '<td style="text-align: right;"><b>'+point.series.name +' : </b></td>'+
                           '<td><b>' + point.y+'</b></td>'+
                       '</tr>');
            });

            s.push('<tr><td style="text-align:right;" colspan="3"><b>تعداد خبر : ' +
             this.points[0].point.NumberNews + '</b></td></tr></table>');                                   
            return s;   
    }
},

The result is same :

Result

My question is: Why top of this tool-tip print some commas? How can I delete those?

thanks

iDeveloper
  • 1,699
  • 22
  • 47
narges
  • 681
  • 2
  • 7
  • 26

2 Answers2

7

You are returning an array. The formatter expects a string to be returned. It seems to print the separator commas from the array entries.

You have the code:

var s = [];
// ...
return s;

Instead you could do (JSFiddle):

var s = [];
// ...
return s.join('');

This just concatenates the array entries with no separator sign.

Halvor Holsten Strand
  • 19,829
  • 17
  • 83
  • 99
1

This is the default string separator for returning array.

tooltip: {
     crosshairs: [true, true],
     shared: true,
     useHTML: true,
     formatter: function() {

        var s = [];
        s.push('<table><tr><td style="text-align:right;" colspan="3"><b>' + 
         this.x + '</b></td></tr>');
        $.each(this.points, function(i, point) {
            s.push('<tr><td style="text-align: right;">'+
                          '<b><span style="color:'+point.series.color +'">\u25CF</span></b>'+
                       '</td>'+
                       '<td style="text-align: right;"><b>'+point.series.name +' : </b></td>'+
                       '<td><b>' + point.y+'</b></td>'+
                   '</tr>');
        });

        s.push('<tr><td style="text-align:right;" colspan="3"><b>تعداد خبر : ' +
         this.points[0].point.NumberNews + '</b></td></tr></table>');                                   
        return s.join(''); //This will removed comma's, if you want to put an string separator just insert it inside the return//   
    }
},
Pang
  • 9,564
  • 146
  • 81
  • 122
JJG
  • 49
  • 3
  • You should also add an explanation in the answer. – Balwinder Singh Jul 21 '16 at 06:44
  • The join() method joins the elements of an array into a string, and returns the string. The elements will be separated by a specified separator. The default separator is comma (,). – JJG Jul 21 '16 at 08:23