Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Based on <a href="https://groups.google.com/forum/?fromgroups#!topic/jqplot-users/Tj737KIhsPo" rel="noreferrer">this</a>, you could use a format string like the following:</p> <pre><code>yaxis: { tickOptions: { formatString: "%'.2f" }, min : 0 } </code></pre> <p>That format string, along with the value, end up as arguments into a call to <code>$.jqplot.sprintf</code>. You can then set the separators as follows:</p> <pre><code>$.jqplot.sprintf.thousandsSeparator = ','; $.jqplot.sprintf.decimalMark = '.'; </code></pre> <p>So this code:</p> <pre><code>var value = 10000; $.jqplot.sprintf.thousandsSeparator = '.'; $.jqplot.sprintf.decimalMark = ','; console.log($.jqplot.sprintf("European %'.2f", value)); $.jqplot.sprintf.thousandsSeparator = ' '; $.jqplot.sprintf.decimalMark = ','; console.log($.jqplot.sprintf("Other %'.2f", value)); $.jqplot.sprintf.thousandsSeparator = ','; $.jqplot.sprintf.decimalMark = '.'; console.log($.jqplot.sprintf("US %'.2f", value)); </code></pre> <p>Will produce this:</p> <pre><code>European 10,000.00 Other 10 000,00 US 10,000.00 </code></pre> <p>However, see how the European one is the same as the US? When those separator settings are changed, it results in string replacement, hence why the European one ends up like it does: replacing commas with periods and then periods with commas gives you back the original string.</p> <p>Because of that, you would need to provide a custom tick formatting method so you could apply those settings on-the-fly and then do a string replace:</p> <pre><code>yaxis: { tickOptions: { tickOptions: { formatString: "%'.2f" }, formatter: function(format, value){ return FormatTick(format, value); } } } .... function FormatTick(format, value) { var prevThousandsSeparator = $.jqplot.sprintf.thousandsSeparator; var prevDecimalMark = $.jqplot.sprintf.decimalMark; $.jqplot.sprintf.thousandsSeparator = '#'; $.jqplot.sprintf.decimalMark = '_'; var formattedValue = $.jqplot.sprintf(format, value); formattedValue = formattedValue.replace($.jqplot.sprintf.decimalMark, Language.DecimalMark) .replace($.jqplot.sprintf.thousandsSeparator, Language.ThousandsSeparator); $.jqplot.sprintf.thousandsSeparator = prevThousandsSeparator; $.jqplot.sprintf.decimalMark = prevDecimalMark; return formattedValue; } </code></pre> <p>This means you will also need some convenient mechanism for establishing both the locale of the user and the correct separator characters to use. I save and restore the <code>thousandsSeparator</code> and <code>decimalMark</code> characters in this way just to ensure that setting them in this way does not cause inadvertant problems elsewhere.</p> <p>Note also that my solution assumes that the <code>#</code> and <code>_</code> characters will not otherwise be in the value you are wanting to format. If this is not so, modify the separators in the <code>FormatTick</code> method to something more suitable.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload