带条形图的NVD3对数Y轴 [英] NVD3 Logarithmic Y axis with barchart

查看:96
本文介绍了带条形图的NVD3对数Y轴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用NVD3制作的条形图,显示的数据在最小值和最大值之间有巨大的差距.

I have a barchart made with NVD3 that shows datas with a huge gap between min value and max value.

这使图表不太好/没用.

This makes the chart not really nice/usefull.

示例:

Y值在4,000到60,000之间,而有些值在3m附近.

Y value are between 4,000 and 60,000 then some value are near 3m.

我希望Y轴值以对数方式增加,显示类似(请参见y轴):

I would like to have an Y Axis value increasing logarithmically, that show something like this (see the y Axis):

我尝试更改yAxis比例,yAxis域,但是没有找到任何可行的解决方案

I tried to change yAxis scale, yAxis Domain, but didn't find any working solution

(仅供参考:我通过angularJs指令使用nvd3)

(FYI: I use nvd3 through angularJs directives)

推荐答案

这将为您服务

chart.y(function(d) { return d.value>0?Math.log10(d.value+1):0 })
chart.yAxis.tickFormat(function(d){return (Math.pow(10,d)-1).toFixed(2)})

仅适用于正值

Works only for positive values

这篇关于带条形图的NVD3对数Y轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆