Garry
Garry

Reputation: 1281

JQplot Format String

Can I please have some help to format the string on the Y Axis that has a '%' sign.

Here is the code for a '$':

tickOptions: {formatString: '$%d'}

How do I format the string to use a '%' sign as the '%' sign is used as a 'keyword'?

Upvotes: 2

Views: 8852

Answers (2)

AnthonyLeGovic
AnthonyLeGovic

Reputation: 2335

To write a '%' sign you have to double it :

axes:
   {yaxis: 
        {tickOptions: 
               {formatString: '%%%d'}
        }
   }

%%%d will write '%10' if your value is 10. Similarly, %d%% will write '10%' if again your value is 10. So you just have to replace the '$' sign by '%%'.

Anthony.

Upvotes: 6

Pablo Claus
Pablo Claus

Reputation: 5920

Try something like this:

tickFormatter = function (format, val) { 
return val+"%";
}

And add this option to the plot:

axes: {
 yaxis: {
 tickOptions: {
  formatter: tickFormatter
 }
}

http://jsfiddle.net/pabloker/9ZrKA/3/

Upvotes: 7

Related Questions