Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

How to add 'range' filter on Line Chart? #15

Open
BorderlessNomad opened this issue Aug 14, 2014 · 4 comments
Open

How to add 'range' filter on Line Chart? #15

BorderlessNomad opened this issue Aug 14, 2014 · 4 comments

Comments

@BorderlessNomad
Copy link

I was wondering if there is any way to add 'range' filter on Line Chart. DC.js mentions about

chart.rangeChart

however there seems to be no way to parse another chart (bar) to that method.

e.g. http://dc-js.github.io/dc.js/#monthly-move-chart

@TomNeyland
Copy link
Owner

@ahirmayur Right now the easiest way to do this is to use the dc-post-setup-chart attribute to pass in a callback function, and then in the callback function add the range chart to your line chart.

Example:

In your html:

<div dc-chart="lineChart" dc-options="myChartOptions" dc-post-setup-chart="setupRangeChart">
    <div id="my-range-chart"></div>
</div>

In your controller:

$scope.myChartOptions = {...}; // An object containing the line chart options

$scope.setupRangeChart = function(myLineChart, chartOptions) {
    var myRangeChart = dc.barChart("#my-range-chart");
    //... setup the range chart
    myLineChart.rangeChart(myRangeChart);
};

However, this is less than elegant, and feels like a leak in the abstraction that angular-dc provides.

A better solution I have been considering is to add a few nestable directives to angular-dc that could be used in the following way:

<div dc-chart="lineChart" dc-options="myChartOptions" dc-post-setup-chart="setupRangeChart">
    <div dc-range-chart dc-dimension="myRangeDimension" dc-group="myRangeGroup"></div>
</div>

Thus avoiding the need for a callback and the need to use dc.js directly from within the controller.

I'll think on this a little more this weekend and let you know if I have implemented a better solution.

@BorderlessNomad
Copy link
Author

Thanks for the response.

At the moment I am using a solution somewhat similar to your callback example. However I would love to see directives directives implemented.

@bwinchester
Copy link

The current code for angular-dc seems to be using an attribute called dc-range-chart for the rangeChart() method. I simply used dc-range-chart="volumeChart" like the example, https://tomneyland.github.io/angular-dc/example/stocks/nasdaq.html , and it works fine. The reset feature of the main chart doesn't reset the rangeChart, but I wrote a fix for that too.

In the angular-dc linking function, look the code that adds a click listener to the 'a.reset' element. Then add a check for dc-range-chart attribute, eval the value and call filterAll on it, like so:

a.on('click', function() {
                        chart.filterAll();
                        if(iAttrs.dcRangeChart){
                            var rangeChart = scope.$eval(iAttrs.dcRangeChart);
                            rangeChart.filterAll();
                        }
                        dc.redrawAll();
                    });

@berendberendsen
Copy link

@bwinchester did you manage to replicate it exactly like the example? I am trying with my own data and what seems to be happening is that the range chart shows up fine, but when I use it to zoom in on a certain period it actually 'filters' out the rest of the rangechart. In other words, the grey bars aren't there which are actually quite helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants