问题
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:
- 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?
- 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.
来源:https://stackoverflow.com/questions/24992280/enable-default-selection-in-bar-chart-of-dc