简体   繁体   English

气泡图 c3js

[英]Bubble chart c3js

Following the c3js documentation there is no option for Bubble chart.按照 c3js 文档,没有气泡图选项。 One workaround for that is to setup scatter plot and specify point radius, but all of the bubbles will be the same height.一种解决方法是设置散点图并指定点半径,但所有气泡都将具有相同的高度。

point = {
          r: function(d) {
             var num = d.value;
             return num
          },

Adding the value of axis inside the r solve the problem, but now the problem is how to setup very high or very low values ?在 r 中添加轴的值解决了问题,但现在的问题是如何设置非常高或非常低的值? For eg if there is 1 000 000 value the whole chart will be colored.例如,如果有 1 000 000 个值,整个图表将被着色。 Is there any simple workarounds for that ?有什么简单的解决方法吗?

First of all, set r to return the square root of your chosen variable eg return sqrt(num), that way a circle representing a data point 100 times the size of another has 100, not 10,000, times the area (area=pi r2 and all that)首先,设置 r 以返回您选择的变量的平方根,例如 return sqrt(num),这样表示一个数据点 100 倍于另一个大小的圆有 100,而不是 10,000,乘以面积 (area=pi r2以及所有这些)

If the numbers are still too big use a linear scale to restrict them to a usable size:如果数字仍然太大,请使用线性比例将它们限制为可用大小:

rscale = d3.scale.linear().domain([1,1000]).range([0,10])

and then return rscale(sqrt(num))然后返回 rscale(sqrt(num))

If your problem is to represent large and small values on the same chart so small values don't disappear and large values don't exceed the chart size look at using a d3 log scale:如果您的问题是在同一个图表上表示大值和小值,那么小值不会消失并且大值不会超过图表大小,请使用 d3 对数刻度查看:

rscale = d3.scale.log().base(10).domain([1,1000]).range([0,10])

Of course on a log scale the areas aren't linearly proportionate any more so whether the sqrt step is necessary is debatable.当然,在对数尺度上,面积不再呈线性比例,因此 sqrt 步骤是否必要是有争议的。 If you don't just remember to adjust the domain to account for this - change it to domain([1,1000000])如果您不记得调整域以解决此问题 - 将其更改为 domain([1,1000000])

if you don't know the size of your numbers beforehand it will be worthwhile looping through your dataset to pick out the min and max to plug into the domain value: domain([your_min, your_max]).如果您事先不知道数字的大小,则值得循环遍历您的数据集以选出最小值和最大值以插入域值:域([your_min,your_max])。 my examples above all assume a max of one million.我上面的例子都假设最多一百万。

Here's an example I forked on jsfiddle, numbers from a few hundred to over a hundred thousand are displayed using a log scale and all are visible but the differences are still obvious:这是我在 jsfiddle 上分叉的一个例子,使用对数刻度显示从几百到十万的数字,所有数字都可见,但差异仍然很明显:

http://jsfiddle.net/m9gcno5n/ http://jsfiddle.net/m9gcno5n/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM