更改nvd3散点图中的y轴标签 [英] change y axis labels in nvd3 scatter-chart

查看:149
本文介绍了更改nvd3散点图中的y轴标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为nvd3中的气泡图设置自己的y轴标签。目前的标签是[1,2,3,4,5]。我想让他们显示为[2,4,8,16,32]。我发现了以下函数:

I am trying to have my own y axis labels for the bubble chart in nvd3. Currently the labels are [1,2,3,4,5]. I want them to be displayed as [2,4,8,16,32]. I found the following function,

chart.yAxis.tickValues(['2','4','8','16','32']);

但标签未被更改此处。我不能理解为什么。

But the labels are not being changed here. I am unable to understand why.

推荐答案

如果 y 值本身不在2-32范围内。现在该图表只有 y 的值高达2 +。

These tick values will not have any effect if the y values themselves are not within the 2-32 range. Right now that chart only has y values up to 2+.

因此,如果除了添加 chart.yAxis.tickValues(['2','4','8','16','32']); 在您的问题中,您还对Data(JSON)标签中的代码进行了以下更改...

So, if in addition to adding chart.yAxis.tickValues(['2','4','8','16','32']); to the Chart Code/Javascript tab as you have in your question, you also make the following change to the code in the Data(JSON) tab...

y: Math.floor(Math.random() * 33) // change from y: random()

。 ..然后你会看到你指定的刻度值(2-32)出现在 y 轴。

...then you will see the tick values you specified (2-32) show up in the y axis.

注意:我假设你正在查看散点/气泡图。

NOTE: I assume you are looking at the Scatter / Bubble Chart.

这篇关于更改nvd3散点图中的y轴标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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