Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
636 views
in Technique[技术] by (71.8m points)

multi select - Enable default selection in bar-chart of dc

So, I have two bar charts plotted using cross-filter and dc. This is how my code looks like:

var barChart2 = dc.barChart("#dc-mv-chart");  
var depValue = facts.dimension(function(d) {return d.d;});
var depValueGroupSum = depValue.group().reduceSum(function(d) {return +d.g;});
var mvValue = facts.dimension(function(d,i) {return d.b;});
      var mvValueGroupSum = mvValue.group().reduceSum(function(d) {return +d.g;});  
      barChart1.width(1200)
            .height(200)
            .margins({top: 10, right: 10, bottom: 20, left: 80})
            .dimension(depValue)                                
            .group(depValueGroupSum)                            
            .transitionDuration(800)
            .centerBar(true)    
            .gap(10)                                            
            .x(d3.scale.ordinal().domain(["AUTO & TIRES", "BABY", "CLOTHING", "ELECTRONICS", "GARDEN", "GROCERY", "HEALTH", "HOME", "HOME IMPROVEMENT", "PHOTO", "SPORTS", "TOYS", "VIDEO GAMES"]))
            .elasticY(true);


        //barChart1.filter = function() {}

          barChart2.width(600)
            .height(300)
            .margins({top: 10, right: 10, bottom: 20, left: 80})
            .dimension(mvValue)                             
            .group(mvValueGroupSum)                         
            .transitionDuration(800)
            .centerBar(true)    
            .gap(20)                                            
            .x(d3.scale.ordinal().domain(["SEM", "SEO", "SOCIAL", "CSE", "ORGANIC", "MOBILEWEB", "AFFILIATES", "EMAIL", "DISPLAYADS"]))
            .elasticY(true)
            .renderHorizontalGridLines(true)
            .xUnits(dc.units.ordinal);      

          // Render the Charts
          dc.renderAll();

However, in my first graph(i.e. barChart1), I want one of the bars to be selected by default i.e. 'Auto & Tires' and also, in the first chart at any time I want only one selection to be made(i.e. disable multi-select for the first graph) So this is what I want to know:

  1. Is it possible to disable multi-select (keeping in mind that there should be only one bar selected in the graph at a time) for a bar graph plotted using dc?
  2. If 1 is possible, then is it possible to keep a default selected bar all the time(by all the time, I mean, on first load when no selection has been made and also,a situation when, say, the user selects 'SPORTS') and deselects it.On de-selection, the graph being shown should be for 'Auto & Tires' which is my default selection)

I am quite new to using dc and cross-filter and haven't found much about the things that I want to implement.So, any help or suggestion of any kind will be appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...