如何从Highcharts 3D列和工具提示中删除小数?

时间:2015-11-06 22:42:07

标签: jquery json highcharts

我已经尝试了我在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
                            }
                        });

1 个答案:

答案 0 :(得分:1)

你应该设置

Highcharts.numberFormat(this.y, 0);

从xAxis中删除小数,你可以使用

xAxis:{             
        allowDecimals: false},

for tooltip

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

请参阅an example fiddle here