Nivo: Legend Series Toggle

Created on 21 May 2018  路  10Comments  路  Source: plouc/nivo

Can we have the legend series toggle on and off the data in the chart?

legends

Most helpful comment

I just figured out how to do this without having to build my own interactive legend component. The key is hidden inside of this storybook: https://nivo.rocks/storybook/?path=/story/waffle--legend-toggle

<ResponsiveLine
    data={ data }
    colors={ this.state.colors || { scheme: 'red_yellow_green' } }
    legends={[
        {
            onClick: (d) => {
                const colors = data.map(series => (series.id === d.id ? '#ff3344' : '#DDD'));
                this.setState({
                    colors: colors,
                });
            },
        },
    ]}
/>

Once you have this, you can also implement a way for the user to deselect the series highlighting.

All 10 comments

@westonnh, unfortunately legends aren't interactives for now, but it can be implemented using your own legends, that's what I did on https://stateofjs.com/2017/connections/

@westonnh, there's a work in progress on https://github.com/plouc/nivo/pull/224 which will add the ability to implement this feature.

[...] but it can be implemented using your own legends, that's what I did on https://stateofjs.com/2017/connections/

@plouc I guess you are referring to this part, right?
https://github.com/StateOfJS/StateOfJS/blob/6de5533a1e003487c229acc119b6f74daf24876e/surveys/2017/website/src/pages/2017/Connections.js#L99-L103

@serchavalos, yes, that's the approach I've used for state of js

I just figured out how to do this without having to build my own interactive legend component. The key is hidden inside of this storybook: https://nivo.rocks/storybook/?path=/story/waffle--legend-toggle

<ResponsiveLine
    data={ data }
    colors={ this.state.colors || { scheme: 'red_yellow_green' } }
    legends={[
        {
            onClick: (d) => {
                const colors = data.map(series => (series.id === d.id ? '#ff3344' : '#DDD'));
                this.setState({
                    colors: colors,
                });
            },
        },
    ]}
/>

Once you have this, you can also implement a way for the user to deselect the series highlighting.

@aiisahik That kinda works as a poor-mans version of this feature, but it doesn't work for stacked ResponsiveLines,

Is there a way to implements the hiddenIds in the ResponsiveLine chart?

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!

This feature would be very useful. Please prioritize when possible. Thank you!

Its this not possible yet? so much need it feature for multiple line charts

Was this page helpful?
0 / 5 - 0 ratings

Related issues

barnapisti1994 picture barnapisti1994  路  3Comments

PattieC4ke picture PattieC4ke  路  3Comments

tj picture tj  路  4Comments

KENNYSOFT picture KENNYSOFT  路  3Comments

vagnervst picture vagnervst  路  4Comments