Google折线图:如何更改工具提示中的小数点?

时间:2013-03-10 18:47:33

标签: google-visualization

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

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

1 个答案:

答案 0 :(得分:0)

Google Charts使用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;
    }
  }
}