Example of Stacked Area Chart http://nvd3.org/ghpages/stackedArea.html
When I click on a series, it expands to all chart area, removing other series. How do I disable this functionality?
Example of Stacked Area Chart http://nvd3.org/ghpages/stackedArea.html
When I click on a series, it expands to all chart area, removing other series. How do I disable this functionality?
The best you can do for now is to disable the legend. You can do that using
chart.showLegend(false)
, or, as an option like:A nasty solution if you don't mind not responding to any mouse event:
Use this on the element.
There isn't any NVD3 chart option to over-ride this behaviour, but you can over-ride the click event handler directly. However, it gets a little complicated with the stacked area chart...
NVD3 uses a
d3.dispatch
object to handle custom events. User clicks and mouseovers and related actions are all converted into these custom events.If you want a function to happen after a custom event, you can call the dispatch object's
.on(eventName, function)
method. If the function parameter isnull
, it cancels out any previous event handling functions attached to that name. (If you want multiple functions to be triggered by the same event, you can add a "namespace" to the event name by using a string of the form"eventName.namespace"
as the first parameter; that function will then only be cancelled ifon
is called again with the exact same event name string.)So to cancel out a behaviour you don't want, you need to check the source code to figure out the name of the custom event that is triggering that behaviour, and call the dispatch object's
on
method with that name and a null function.Here's where it gets complicated. There are actually multiple different events that cause a data series to be toggled on and off. If you click on the area, if you click on the legend, or if you click on one of the scatterpoint circles that appear when you mouseover, you get the same behaviour. So all of those events have to be over-written. And they're not even all part of the same dispatch object: The main chart object itself has a dispatch object that handles the complete redraw events created by clicking the chart layout controls, but the click events on the stacked areas are handled by an internal charting function that draws the plotting area, the click events on the scatterpoints are handled by an internal charting function within that, and the click events on the legend are handled within the legend function.
And here's where it gets really complicated. When the chart as a whole is updated or its layout changed, those internal chart-drawing functions for the plotting area and the scatterplot get over-written by the main chart function. Which means all the events get reset to their NVD3 defaults.
So not only do you have to disable all the events that trigger the behaviour, you also have to modify the update function to disable them all again. And because the update function itself is reset every update,* you need to include the modification of the update function as part of the function you use to disable the events.
**The update function just re-calls the entire chart drawing function using the same container selection. One of the first lines of the chart function creates the update function.*
Here's the code, based on the Stacked Area example on the nvd3.org live code page: