React-vis: Legends for charts with multiple series

Created on 17 Mar 2016  路  4Comments  路  Source: uber/react-vis

I've been pondering this for the last couple days, working out a means of building a legend with interactivity hooks into the existing XY chart series.

Perhaps something like this could work as a starter - wrapping a higher order component around the series components. This component would essentially be an interface rendering a 'default legend' and include event handlers to do things like filtering on selection of a specific series.

<XYPlot
  width={300}
  height={300}>
  <HorizontalGridLines />
  <Legend onSelection={this.onSelection} style={style}>
    <LineSeries
      color='red'
      data={[
        {x: 1, y: 10},
        {x: 2, y: 5},
        {x: 3, y: 15}
      ]}/>
    <LineSeries
      color='blue'
      data={[
        {x: 1, y: 10},
        {x: 2, y: 5},
        {x: 3, y: 15}
      ]}/>
  </Legend>
  <XAxis />
  <YAxis />
</XYPlot>

An alternative would be just to have a standalone <Legend/> component that is fed information about series the chart from the XYPlot - potentially less complexity there, I guess.

Would appreciate thoughts (or alternative approaches!) on this, and happy to help with PR to get it landed.

enhancement

Most helpful comment

@samhogg , Yes, Sam, I have legends in the roadmap. It's not the most needed feature, but quite important though.

Thank you for you proposal. Yes, this is one of the ways to implement legends. However, legend placement differs from one vis to another. The number of items in legends may vary significantly as well.

We are considering creating standalone legend components and then providing an obvious (and optional) way to connect legends to a chart. I'll create a task for that shortly.

All 4 comments

I guess an example wouldn't hurt - I'm thinking something along the lines of this (from plotly.js)
newplot

@samhogg , Yes, Sam, I have legends in the roadmap. It's not the most needed feature, but quite important though.

Thank you for you proposal. Yes, this is one of the ways to implement legends. However, legend placement differs from one vis to another. The number of items in legends may vary significantly as well.

We are considering creating standalone legend components and then providing an obvious (and optional) way to connect legends to a chart. I'll create a task for that shortly.

@bulyonov cool! Yeah the positioning thing could get quite complex. The easiest way would probably be to have the legend as an overlay on the chart (absolutely positioned) and able to be hidden by a user if it's concealing data.

@samhogg yes, this is one of the options. The other option is to keep the legend _outside_ of the chart and provide a simple and easy way to connect it with the visualization.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

martoncsikos picture martoncsikos  路  4Comments

jonnydodad picture jonnydodad  路  4Comments

cang-afero picture cang-afero  路  4Comments

Falieson picture Falieson  路  3Comments

mcnuttandrew picture mcnuttandrew  路  3Comments