如何在图表API x / y轴标签中显示整数(无小数) [英] How to show only integers (no decimals) in chart API x/y-axis labels
问题描述
我正在使用Google Chart JS Api的柱状图。我正在显示一些只能用整数表示的值(每天的总订单)。
I'm using a column chart with the Google Chart JS Api. I'm displaying some values (total orders by day) that can only be represented as integers.
一切都很好,除了当我显示的一个图表的值太低时,比如1或2,它开始显示小数点y轴。小数点看起来愚蠢的b / c不可能有一个一半的订单(这就是我的计数),我想隐藏这个如果可能的话。
Everything is working great, except that when one of the charts I'm displaying has values that are too low, like 1 or 2, it starts to show decimals on the y-axis. The decimals look silly b/c it's impossible to have "half" an order (which is what I'm counting), and I'd like to hide this if possible.
推荐答案
注意:请参阅 https://stackoverflow.com/a/16036721 / 390977 ,因为我的回答不正确。 (我无法删除它,因为它已被接受。)
Note: Please see https://stackoverflow.com/a/16036721/390977, as my answer is incorrect. (I can't delete it because it was accepted.)
在您的选项中,您可以指定chxs值的数字格式:
In your options you can specify number formatting for the chxs value:
chxs: '0N*f0*,
它使用一个浮点值( f
),其中0为小数( f0
)。
This uses a float value (f
) with 0 decimals (f0
).
http://code.google.com/apis/chart/image/docs/gallery/bar_charts.html#axis_label_styles
这篇关于如何在图表API x / y轴标签中显示整数(无小数)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!