简体   繁体   English

Crossfilter和dc.js平均值

[英]Crossfilter and dc.js mean value

I have this data set: 我有这个数据集:

tick    ID    Name    val1    val2    val3    val4
0       1     Name1    0.7    0.1       0.2    0.1
1       2     Name2    0.8    0.1       0.1    0.1
2       3     Name3    0.4    0.1       0.2    0.3
3       4     Name4    0.6    0.1       0.2    0.1
4       1     Name1    0.7    0.1       0.2    0.1
5       2     Name2    0.8    0.1       0.1    0.1
6       3     Name3    0.4    0.1       0.2    0.3
7       4     Name4    0.6    0.1       0.2    0.1

I already visualized everything with crossfilter and dc.js, except one diagram. 除了一张图,我已经使用crossfilter和dc.js可视化了所有内容。 I want the mean value of the column val1, val2, val3 and val4. 我想要列val1,val2,val3和val4的平均值。

在此处输入图片说明

I have visualized this map with dc.js alread. 我已经使用dc.js可视化了此地图。 The ID in the data is a segement in the image. 数据中的ID是图像中的细分。 The ticks are rounds, for instance the object with id 1 at tick 2 has the values 0.7, 0.1, 0.2 and 0.1. 刻度是圆形的,例如,刻度2处ID为1的对象的值分别为0.7、0.1、0.2和0.1。 So the mean data should be connected to the segments. 因此,均值数据应连接到段。 For instance when only the blue object with ID 1 is selected it should show the mean of the current selection: 例如,当仅选择ID为1的蓝色对象时,它应显示当前选择的平均值:

tick    ID    Name    val1    val2    val3    val4
0       1     Name1    0.7    0.1       0.2    0.1
4       1     Name1    0.7    0.1       0.2    0.1

If I select a second object with ID 2, it should show the mean value of the both segments: 如果选择ID为2的第二个对象,则应显示两个分段的平均值:

在此处输入图片说明

tick    ID    Name    val1    val2    val3    val4
0       1     Name1    0.7    0.1       0.2    0.1
1       2     Name2    0.8    0.1       0.1    0.1
4       1     Name1    0.7    0.1       0.2    0.1
5       2     Name2    0.8    0.1       0.1    0.1

Maybe I can show then the mean values of the two object in an pie chart. 也许我可以在饼图中显示两个对象的平均值。 Where I can see the mean of the four classes val1, val2, val3 and val4. 在这里我可以看到四个类val1,val2,val3和val4的平均值。 So I want to set them in relation like: 所以我想将它们设置为如下关系:

Sum val1 3
Sum val2 0.4
Sum val3 0.6
Sum val4 0.4

Sum all 4.4

So the classes would have the following size on the pie chart: 因此,这些类在饼图中的大小如下:

val1 3/4.4 = 0.68 = 68 percent
val2 0.4/4.4 = 0.090 = 9 percent
val3 ...
val4 ...

在此处输入图片说明

How can I accomplish this, because this was the only visualization that didn't worked. 我如何完成此操作,因为这是唯一无效的可视化。

It's funny how many different ways people explain how their data is structured and the result they need. 有趣的是,人们解释了数据结构和所需结果的不同方式。 Even with great detail explanation sometimes the message doesn't come across. 即使进行了非常详细的说明,有时也不会出现此消息。 Anyway I heard this post as being similar to my post . 无论如何,我听说这则帖子与我的帖子相似。 Gordon suggested I use reductio . 戈登建议我使用还原法 However I dug into some other posts I ended up using the add remove initial methods. 但是,我深入研究了其他一些帖子,最终使用了add remove初始方法。 I created a jsfiddle that gives you the percent per name. 我创建了一个jsfiddle ,为您提供每个名称的百分比。 I would like to know from others more skilled with DC if this is being done correctly, or not. 我想从其他DC熟练的人那里了解是否正确完成了这项工作。

   var data = d3.csv.parse( d3.select("pre#data").text() );     
            data.forEach(function (d) {
            d.tick = +d.tick
            d.id = +d.ID;
            d.name = d.Name;
            d.val1 = +d.val1;
            d.val2 = +d.val2;
            d.val3 = +d.val3;
            d.val4 = +d.val4;
        });

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

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