user3438326
user3438326

Reputation: 89

Filtering the data values so as to obtain only necessary values in one of the chart

consider the example http://jsfiddle.net/5D5eD/18/. In the chart on the top how to set a filter to the datavalues so as to obtain only those points on the chart that I want. For example the datavalues are

[2,2],
[3,3],
[4,4],
[5, 4],
[5.5, 5],
[6, 6],
[6, 7],
[7,8],
[7,9],
[8,10],
[8,11]

I would like to have these datavalues on the chart at the bottom, whereas the chart on the top must have only these values

[3,3]
[6,6]
[8,10]

How to set this filtering condition ?

Upvotes: 0

Views: 55

Answers (1)

jing3142
jing3142

Reputation: 1871

Easiest way seems to tag them B=true for both, L=false for lower. Have amended the fiddle to incorporate the following changes and additions.

var B=true;  //draw in both main and other
var L=false; //draw in other only
var data = [

    [2,2, L],
    [3,3, B],
    [4,4, L],
    [5, 4, L],
    [5.5, 5, L],
    [6, 6, B],
    [6, 7, L],
    [7,8, L],
    [7,9, L],
    [8,10, B],
    [8,11, L]

];

and these

var filteredData=[];
for(var i=0; i<data.length; i++) {
    if(data[i][2]) {
        filteredData.push(data[i]);
    }
}

drawGraph(main, false, filteredData);
drawGraph(other, true, data);

function drawGraph(element, drawLine, data) {

        *//rest of function unchanged*

I am not familiar with D3 so did filtering before D3 used. Hope this helps

Upvotes: 1

Related Questions