【问题标题】:Google Line Chart: How to change decimal mark in tooltips?谷歌折线图:如何更改工具提示中的小数点?
【发布时间】:2013-03-10 18:47:33
【问题描述】:

https://google-developers.appspot.com/chart/interactive/docs/gallery/linechart#Example

如何将工具提示中的小数点从句点更改为逗号?

【问题讨论】:

  • 工具提示目前不包含任何句点?
  • 不在示例中,您是对的。但是如果你写“1000.0”而不是“1000”,他们会这样做。

标签: google-visualization


【解决方案1】:

Google 图表使用ICU DecimalFormat Class 的子集。不幸的是,据我所知,该子集不包括更改语言环境的能力。如果您确实想尝试,您可以尝试使用使用逗号作为小数分隔符的区域设置(例如欧洲)的此 javascript 版本(这会打印出所有区域设置信息,因此您必须深入研究参考以找出如何首先设置单个语言环境):

// Normally we would have a GUI with a menu for this
int32_t locCount;
const Locale* locales = NumberFormat::getAvailableLocales(locCount);
double myNumber = -1234.56;
UErrorCode success = U_ZERO_ERROR;
NumberFormat* form;
// Print out a number with the localized number, currency and percent
// format for each locale.
UnicodeString countryName;
UnicodeString displayName;
UnicodeString str;
UnicodeString pattern;
Formattable fmtable;
for (int32_t j = 0; j < 3; ++j) {
  cout << endl << "FORMAT " << j << endl;
  for (int32_t i = 0; i < locCount; ++i) {
    if (locales[i].getCountry(countryName).size() == 0) {
      // skip language-only
      continue;
    }
    switch (j) {
      case 0:
        form = NumberFormat::createInstance(locales[i], success ); break;
      case 1:
        form = NumberFormat::createCurrencyInstance(locales[i], success ); break;
      default:
        form = NumberFormat::createPercentInstance(locales[i], success ); break;
    }
    if (form) {
      str.remove();
      pattern = ((DecimalFormat*)form)->toPattern(pattern);
      cout << locales[i].getDisplayName(displayName) << ": " << pattern;
      cout << " -> " << form->format(myNumber,str) << endl;
      form->parse(form->format(myNumber,str), fmtable, success);
      delete form;
    }
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-20
    相关资源
    最近更新 更多