Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

add a single select example using addFilterHandler() #1477

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions web/examples/bar-single-select-add-filter-handler.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>dc.js - Bar Chart Example</title>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="../css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="../css/dc.css"/>
</head>
<body>

<div class="container">
<script type="text/javascript" src="header.js"></script>
<p>Frequently asked question: how to enable single-select on an ordinal chart?</p>

<div id="test">
<div>
<a class="reset" style="visibility: hidden" href="javascript:chart.filterAll();dc.redrawAll();">reset</a>
</div>
</div>

<script type="text/javascript" src="../js/d3.js"></script>
<script type="text/javascript" src="../js/crossfilter.js"></script>
<script type="text/javascript" src="../js/dc.js"></script>
<script type="text/javascript">

var chart = dc.barChart("#test");
d3.csv("morley.csv").then(function(experiments) {

experiments.forEach(function(x) {
x.Speed = +x.Speed;
});

var ndx = crossfilter(experiments),
runDimension = ndx.dimension(function(d) {return +d.Run;}),
speedSumGroup = runDimension.group().reduceSum(function(d) {return d.Speed * d.Run / 1000;});

chart
.width(768)
.height(480)
.x(d3.scaleBand())
.xUnits(dc.units.ordinal)
.brushOn(true)
.yAxisLabel("This is the Y Axis!")
.dimension(runDimension)
.group(speedSumGroup)
.controlsUseVisibility(true)
.addFilterHandler(function(filters, filter) {return [filter];});
chart.render();
});

</script>

</div>
</body>
</html>
19 changes: 10 additions & 9 deletions web/examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,69 +15,70 @@ <h2>Examples of using dc.js</h2>
<td><a href="bar-single-select.html">bar single select</a></td>
</tr>
<tr>
<td><a href="bar-single-select-add-filter-handler.html">bar single select(addFilterHandler)</a></td>
<td><a href="bar.html">bar</a></td>
<td><a href="boxplot-basic.html">boxplot basic</a></td>
<td><a href="boxplot-enhanced.html">boxplot enhanced</a></td>
<td><a href="boxplot-render-data.html">boxplot render data</a></td>
<td><a href="boxplot-time.html">boxplot time</a></td>
</tr>
<tr>
<td><a href="boxplot-time.html">boxplot time</a></td>
<td><a href="cbox-menu.html">cbox menu</a></td>
<td><a href="complex-reduce.html">complex reduce</a></td>
<td><a href="composite-brush-multi-dim.html">composite brush multi dim</a></td>
<td><a href="composite.html">composite</a></td>
<td><a href="download-table.html">download table</a></td>
</tr>
<tr>
<td><a href="download-table.html">download table</a></td>
<td><a href="filter-stacks.html">filter stacks</a></td>
<td><a href="filtering-removing.html">filtering removing</a></td>
<td><a href="filtering.html">filtering</a></td>
<td><a href="heat.html">heat</a></td>
<td><a href="heatmap-filtering.html">heatmap filtering</a></td>
</tr>
<tr>
<td><a href="heatmap-filtering.html">heatmap filtering</a></td>
<td><a href="html-legend.html">html legend</a></td>
<td><a href="line.html">line</a></td>
<td><a href="multi-focus.html">multi focus</a></td>
<td><a href="multi-scatter.html">multi scatter</a></td>
<td><a href="number.html">number</a></td>
</tr>
<tr>
<td><a href="number.html">number</a></td>
<td><a href="ordinal-bar.html">ordinal bar</a></td>
<td><a href="ordinal-line.html">ordinal line</a></td>
<td><a href="pie-external-labels.html">pie external labels</a></td>
<td><a href="pie.html">pie</a></td>
<td><a href="range-series.html">range series</a></td>
</tr>
<tr>
<td><a href="range-series.html">range series</a></td>
<td><a href="replacing-data.html">replacing data</a></td>
<td><a href="right-axis.html">right axis</a></td>
<td><a href="row-top-axis.html">row top axis</a></td>
<td><a href="row-vertical-line.html">row vertical line</a></td>
<td><a href="row.html">row</a></td>
</tr>
<tr>
<td><a href="row.html">row</a></td>
<td><a href="scatter-brushing.html">scatter brushing</a></td>
<td><a href="scatter-series.html">scatter series</a></td>
<td><a href="scatter.html">scatter</a></td>
<td><a href="select.html">select</a></td>
<td><a href="series.html">series</a></td>
</tr>
<tr>
<td><a href="series.html">series</a></td>
<td><a href="sparkline.html">sparkline</a></td>
<td><a href="splom.html">splom</a></td>
<td><a href="stacked-bar.html">stacked bar</a></td>
<td><a href="sunburst-cat.html">sunburst cat</a></td>
<td><a href="sunburst-with-value-accessor.html">sunburst with value accessor</a></td>
</tr>
<tr>
<td><a href="sunburst-with-value-accessor.html">sunburst with value accessor</a></td>
<td><a href="sunburst.html">sunburst</a></td>
<td><a href="switching-time-intervals.html">switching time intervals</a></td>
<td><a href="table-on-aggregated-data.html">table on aggregated data</a></td>
<td><a href="table-pagination.html">table pagination</a></td>
<td><a href="text-filter-widget.html">text filter widget</a></td>
</tr>
<tr>
<td><a href="text-filter-widget.html">text filter widget</a></td>
<td><a href="time-intervals.html">time intervals</a></td>
</tr>
</table>
Expand Down