Skip to content

Commit

Permalink
example of ordinal single selection
Browse files Browse the repository at this point in the history
e.g. for #996
  • Loading branch information
gordonwoodhull committed Aug 25, 2015
1 parent 45721db commit b82ec10
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 4 deletions.
55 changes: 55 additions & 0 deletions web/examples/bar-single-select.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/dc.css"/>
</head>
<body>

<p>Frequently asked question: how to enable single-select on an ordinal chart?</p>

<div id="test">
<a class="reset" style="display: none" href="javascript:chart.filter(null).redrawGroup()">reset</a>
</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", function(error, 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.scale.ordinal())
.xUnits(dc.units.ordinal)
.brushOn(true)
.yAxisLabel("This is the Y Axis!")
.dimension(runDimension)
.group(speedSumGroup)
.on('pretransition', function(chart) {
chart.selectAll("rect.bar").on("click", function (d) {
console.log('click');
chart.filter(null)
.filter(d.data.key)
.redrawGroup();
});
});
chart.render();
});

</script>

</body>
</html>
9 changes: 5 additions & 4 deletions web/examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,33 @@ <h2>Examples of using dc.js</h2>
<tr>
<td><a href="area.html">area</a></td>
<td><a href="bar-extra-line.html">bar extra line</a></td>
<td><a href="bar-single-select.html">bar single select</a></td>
<td><a href="bar.html">bar</a></td>
<td><a href="box-plot-time.html">box plot time</a></td>
<td><a href="box-plot.html">box plot</a></td>
<tr>
<tr>
<td><a href="box-plot.html">box plot</a></td>
<td><a href="composite.html">composite</a></td>
<td><a href="cust.html">cust</a></td>
<td><a href="heat.html">heat</a></td>
<td><a href="heatmap-filtering.html">heatmap filtering</a></td>
<td><a href="line.html">line</a></td>
<tr>
<tr>
<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>
<td><a href="ord.html">ord</a></td>
<td><a href="pie.html">pie</a></td>
<tr>
<tr>
<td><a href="pie.html">pie</a></td>
<td><a href="right-axis.html">right axis</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="series.html">series</a></td>
<tr>
<tr>
<td><a href="series.html">series</a></td>
<td><a href="stacked-bar.html">stacked bar</a></td>
<td><a href="table-on-aggregated-data.html">table on aggregated data</a></td>
<tr>
Expand Down

0 comments on commit b82ec10

Please sign in to comment.