简体   繁体   中英

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. I want the mean value of the column val1, val2, val3 and val4.

在此处输入图片说明

I have visualized this map with dc.js alread. The ID in the data is a segement in the image. 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. 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:

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:

在此处输入图片说明

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. 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. I created a jsfiddle that gives you the percent per name. I would like to know from others more skilled with DC if this is being done correctly, or not.

   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;
        });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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