nvd3与对数标度的泡影图 [英] nvd3 Bubble chart with log scale

查看:136
本文介绍了nvd3与对数标度的泡影图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用NVD3散射/气泡图。这是问题此处的延续。我绘制y轴的对数2的基础值。但我想要y轴具有原始值作为对应于对数基2标度的标签。



这是

  data [i] .values.push({
x:random()
,y:log2(yValue)
,size:Math.random()
});

function log2(val){
console.log(val =+ val +:+ Math.log(val)/ Math.LN2)
return Math .log(val)/ Math.LN2;
}

现在,y轴刻度具有log2值。



感谢,

解决方案

在创建数据数组时,不要直接计算日志,请保持原样,然后使用

要在NVD3中使用自定义缩放,您需要传递它作为 chart.yScale(scale) chart.xScale(scale)方法的参数。

  var chart = nv.models.lineChart()
.yScale(d3.scale.log());

只是不要尝试在条形图或面积图中使用对数标度来表示y值,因为那些在域中自动包含0(如果您尝试在 log(0)!上绘制任何内容,则会出现错误)



有几个警告:




  • 你可能想把它作为默认值。


  • .nice()似乎在对数尺度上工作非常有效;当我在NVD3实时代码站点上玩时,[1,99]的域导致轴上的最终tick值为98.999999999。




另外请注意,由于您的帐户从来没有真正处理日志的计算值(只是与相对位置在规模上),你不需要指定一个基数对数。文档提及 logScale.base(number)方法,但似乎已过时...


I am using NVD3 scatter/ Bubble chart. This is a continuation from the question here. I am plotting the log base 2 values for the y axis. But I want the y axis to have the original values as labels corresponding to the log base 2 scale. I am unable to understand how to do so.

Edit

This is what I have for plotting

data[i].values.push({
    x: random()
  , y: log2(yValue)
  , size: Math.random()
  });

function log2(val) {
console.log("val = " + val + " : " + Math.log(val) / Math.LN2)
    return Math.log(val) / Math.LN2;
}

Now, the y axis ticks have the log2 values. I want to change the y axis ticks to have the original values displayed and not the log2 values.

Thanks,

解决方案

Instead of directly calculating the log when you create your data array, leave it as is and then use a log scale for your axis.

To use a custom scale in NVD3, you pass it as a parameter to the chart.yScale(scale) or chart.xScale(scale) methods.

var chart = nv.models.lineChart()
      .yScale( d3.scale.log() );

Just don't try to use a log scale for y values in a bar or area chart, since those automatically include 0 in the domain (and you'll get errors if you try to plot anything at log(0)!)

A couple warnings:

  • Tick formating functions work different on log scales than for other scales; you'll probably want to just leave it as the default. See the docs (link above) for more info.

  • The .nice() method doesn't seem to work very effectively on log scales; when I was playing around on the NVD3 live code site, a domain of [1,99] was resulting in a final tick value of 98.999999999 on the axis. You may want to explicitly check that the domain starts and ends at round numbers.

Also note that since you're never actually dealing with the calculated values for the logs (just with the relative positions on the scale) you don't need to specify a base to the logarithm. The docs mention a logScale.base(number) method but that seems to be obsolete...

这篇关于nvd3与对数标度的泡影图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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