Highcharts:用逗号格式化所有数字?

时间:2015-03-23 11:50:22

标签: javascript highcharts

我使用的是Highcharts,我想格式化图表中任何位置显示的所有数字(工具提示,轴标签......),以逗号分隔数千个。

否则,默认的工具提示和标签很棒,我希望它们完全相同。

例如,在此图表中,数字应为2,581,326.31,但在其他方面完全相同。

enter image description here

我该怎么做?

我尝试添加:

    tooltip: {
        pointFormat: "{point.y:,.0f}"
    }

但是这摆脱了工具提示中的漂亮圈子和系列标签 - 我想保留它。理想情况下,我更喜欢在整个图表中使用单个选项来设置全局数字格式。

4 个答案:

答案 0 :(得分:110)

可以使用thousandSepAPI)全局选项设置。

Highcharts.setOptions({
    lang: {
        thousandsSep: ','
    }
});

请参阅this JSFiddle example

答案 1 :(得分:3)

如果您想显示不带逗号和空格的数字。

例如默认情况下9800显示为9800。

如果您希望9800显示为9800

您可以在工具提示中尝试以下操作:

    tooltip: {
     pointFormat: '<span>{point.y:.f}</span>'
   }

答案 2 :(得分:2)

这种方式与我合作。

我在yAxis选项中进行了配置。

yAxis: {
  labels: {
    formatter: function() {
        return Highcharts.numberFormat(this.value, 2);
    }
  }
}

答案 3 :(得分:0)

这种方式对我有用。

我使用 Angular 10,我为 Tooltip 和 yAxis 做了这个。

对于 yAxis 使用 numberFormat:

 labels: {
              format: '{value}',
              style: {
                color: Highcharts.getOptions().colors[0]
              },
              formatter: function() {
                return Highcharts.numberFormat(this.value, 3);
            }
            },

和工具提示:

{point.y:.f}
相关问题