Jquery JQPlot-基于区域设置记号格式

Jquery JQPlot-基于区域设置记号格式,jquery,jqplot,number-formatting,Jquery,Jqplot,Number Formatting,如何格式化jqplot中的记号以处理、和之间的更改。和“”取决于我所在的地区 比如说 欧洲-1.000,00 美国-1000.00 其他1000,00 我的示例jqplot初始化如下所示 plot3 = $.jqplot('saturationChart', lineArray, { title:m_Language.saturationChartName, series:lineColor, legend:{

如何格式化jqplot中的记号以处理、和之间的更改。和“”取决于我所在的地区

比如说

  • 欧洲-1.000,00
  • 美国-1000.00
  • 其他1000,00
我的示例jqplot初始化如下所示

plot3 = $.jqplot('saturationChart', lineArray, 
         { 
          title:m_Language.saturationChartName,
          series:lineColor,
          legend:{show:true, location:'se'},
          // You can specify options for all axes on the plot at once with
          // the axesDefaults object.  Here, we're using a canvas renderer
          // to draw the axis label which allows rotated text.
          axes:{
            xaxis:{
//            label:'Minutes',
              renderer: $.jqplot.LogAxisRenderer,
              tickDistribution:'power',
              labelRenderer: $.jqplot.CanvasAxisLabelRenderer,
              labelOptions: {
                //fontSize: '12pt'
              },
            },
            yaxis:{
//            label:'Megaohms',
              renderer: $.jqplot.LogAxisRenderer,
              tickDistribution:'power',
              labelRenderer: $.jqplot.CanvasAxisLabelRenderer,
              labelOptions: {
                //fontSize: '12pt'
              }
            },
          }
      });
我查看了文档,但我不确定我需要查找哪些关键字。。。如果您有任何帮助,我们将不胜感激。基于此,您可以使用如下格式字符串:

yaxis: {
    tickOptions: { formatString: "%'.2f" },
    min : 0
}
该格式字符串以及值最终作为参数进入到对
$.jqplot.sprintf
的调用中。然后可以按如下方式设置分隔符:

$.jqplot.sprintf.thousandsSeparator = ',';
$.jqplot.sprintf.decimalMark = '.';
所以这个代码:

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));
将产生以下结果:

European 10,000.00 
Other 10 000,00 
US 10,000.00 
但是,看看欧洲的和美国的是什么样的?当这些分隔符设置被更改时,会导致字符串替换,因此,欧洲的分隔符最终会变成这样:用句点替换逗号,然后用逗号替换句点,返回原始字符串

因此,您需要提供自定义的勾号格式设置方法,以便可以动态应用这些设置,然后执行字符串替换:

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;
}
这意味着您还需要一些方便的机制来建立用户的区域设置和要使用的正确分隔符。我以这种方式保存和恢复
thousandsSeparator
decimalMark
字符,只是为了确保以这种方式设置字符不会在其他地方引起意外问题


另外请注意,我的解决方案假定
#
字符将不在您想要格式化的值中。如果不是这样,请将
FormatTick
方法中的分隔符修改为更合适的分隔符。

了解到我可以只设置$.jqplot.sprintf.000ansparator和$.jqplot.sprintf.decimalMark,从而解决了仅德语页面的问题。谢谢!