【问题标题】:Highchart: how to add commas to output to intergersHighchart:如何将逗号添加到输出到整数
【发布时间】:2016-03-22 17:20:03
【问题描述】:

我有以下代码从 JSON 数据生成基本面积图,在图表上我希望能够显示逗号分隔的数字而不是整个整数,即图表中的所有数字都应该用逗号显示为 483,533,30 而不仅仅是 48353330。

我按照各种示例中的建议添加了这一点,但似乎不起作用

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

我的工作代码可以在这里看到fiddle

$(document).ready(function() {
    Highcharts.setOptions({
                    lang: {
                        thousandsSep: ','
                    }
                });

var options = {
                chart: {
                    renderTo: 'container',
                    type: 'area',
                    marginRight: 130,
                    marginBottom: 25
                },
                title: {
                    text: 'Deposit Institution',
                    x: -20 //center
                },
                subtitle: {
                    text: '',
                    x: -20
                },
                xAxis: {
                    categories: []
                },
                yAxis: {
                    title: {
                        text: 'Amount'
                    },
                    plotLines: [{
                        value: 0,
                        width: 1,
                        color: '#808080'
                    }]
                },
                tooltip: {
                    formatter: function() {
                            return '<b>'+ this.series.name +'</b><br/>'+
                            this.x +': $'+ this.y;
                    }
                },
                legend: {
                    layout: 'vertical',
                    align: 'right',
                    verticalAlign: 'top',
                    x: -10,
                    y: 100,
                    borderWidth: 0
                },
                series: []
            }

                     $.getJSON("data1.json", function(json) {
                options.xAxis.categories = json[0]['data'];
                options.series[0] = json[1];
                options.series[1] = json[2];
                chart = new Highcharts.Chart(options);
            });


        });

【问题讨论】:

    标签: jquery json highcharts


    【解决方案1】:
    tooltip: {
      formatter: function() {
        return '<b>' + this.series.name + '</b><br/>' +
          this.x + ': $' + Highcharts.numberFormat(this.y, 0, '', ',');
      }
    }
    

    尝试将 Highcharts.numberFormat 添加到您的工具提示格式化程序函数中 http://api.highcharts.com/highcharts#Highcharts.numberFormat

    【讨论】:

      【解决方案2】:

      用 X 或 Y 试试这个:

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

      【讨论】:

      • 谢谢我尝试了它在 y 轴上放逗号的方法,我没有把逗号放在图表本身中
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-10
      • 2015-07-14
      • 2013-12-28
      • 2021-03-13
      • 1970-01-01
      相关资源
      最近更新 更多