【问题标题】:How to drop the decimals from Highcharts 3D columns and tooltip?如何从 Highcharts 3D 列和工具提示中删除小数?
【发布时间】:2015-11-06 22:42:06
【问题描述】:

我已经尝试了我在 Highcharts API 中找到的所有内容,我真的不知道为什么它不会更新。如果有人能指出我正确的方向,就如何正确地写出来或者这些信息在 API 中的位置,那就太好了,谢谢你的时间。

 $(document).ready(function() {
                        var options = {
                            // basic chart options
                            chart: {
                                height: 300,
                                renderTo: 'container',
                                type: 'column',
                                marginRight: 130,
                                lang: {
                                    thousandsSep: ','
                                },
                                marginBottom: 25,
                                // 3D initialization, comment out for non-3D columns
                                 options3d: {
                                                enabled: true,
                                                alpha: 0,
                                                beta: 2,
                                                depth: 50,
                                                viewDistance: 25
                                            }
                            },
                            // main chart title (TOP)
                            title: {
                                text: 'Giving Trends',
                                x: -20 //center
                            },
                            // main chart sub-title (TOP)
                            subtitle: {
                                text: 'By Party of Filer',
                                x: -20
                            },
                            // xAxis title
                            xAxis: {
                                reversed: false,
                                title: {
                                    text: 'Party'
                            },
                                categories: []
                            },
                            // yAxis title
                            yAxis: {
                                title: {
                                    text: 'Dollar Amount'
                                },
                                // chart options for each plotted point
                                plotLines: [{
                                    value: 1,
                                    width: 1,
                                    color: '#66837B'
                                }]
                            },
                            // tooltip on hover options
                            tooltip: {
                                lang: {
                                    thousandsSep: ','
                                },
                                formatter: function() {
                                        return '<b>'+ this.series.name +'</b><br/>'+
                                        this.x +': '+ this.y
                                }
                            },
                            legend: {
                                layout: 'horizontal',
                                align: 'left',
                                verticalAlign: 'top',
                                x: 0,
                                y: 0,
                                borderWidth: 0,
                            },
                             plotOptions: {
                                bar: {
                                dataLabels: {
                                    enabled: true,
                                    color: '#F2C45A'
                                    }
                                },
                                allowDecimals: {
                                    enabled: false
                                },
                                series: {
                                    text: 'Total Dollar Amount',
                                    color: '#66837B',
                                    cursor: 'pointer',
                                    connectNulls: true,
                                    pointWidth: 50
                                },
                                column: {
                                    stacking: 'normal',
                                    dataLabels: {
                                        enabled: true,
                                        color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || '#F2C45A',

                                    }
                                }
                            },
                            series: []

                        }

                        Highcharts.setOptions({
                            // sets comma for thousands separator
                            lang: {
                                thousandsSep: ','
                            },
                            tooltip: {
                                xDecimals: -2 // If you want to add 2 decimals
                            }
                        });

【问题讨论】:

    标签: jquery json highcharts


    【解决方案1】:

    你应该设置

    Highcharts.numberFormat(this.y, 0);
    

    要摆脱 xAxis 中的小数,您可以使用

    xAxis:{             
            allowDecimals: false},
    

    工具提示

    formatter: function() {
    return   Highcharts.numberFormat(this.percentage, 0);
     }
    

    an example fiddle here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-24
      • 2016-09-13
      • 1970-01-01
      • 1970-01-01
      • 2022-07-14
      相关资源
      最近更新 更多