question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Charts: interactive legend

See original GitHub issue

Is there any plan to have a built-in interactive legend as there was in pf3 / c3 charts ? Previously, clicking on legend icons would show/hide the related series in charts.

With victory chart I believe there’s no such mechanism built-in, but we can implement it through events. I’m doing something like that in Kiali: https://github.com/kiali/kiali-ui/pull/1457/commits/63d400d58c2fdcbbb4a77c087c2b76511be6801e#diff-82e26dca83e13db6b8969687fd9268cbR71-R156 . Maybe that can be part of the patternfly value-added & standard look n feel?

Also note that, currently I cannot do it using the ChartLegend component from PF4, as it seems events are not fired when targeting the legend (I believe it’s due to the wrapping component) so I need to use VictoryLegend directly instead of ChartLegend.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
dlabrecqcommented, Oct 7, 2019

FYI @jotak, I created a POC with you’re implementation. The POC relies on the theme to coordinate colors between ChartArea, ChartScatter, and the custom ChartLegend – not necessary to use custom colors.

I also fixed ChartLegend so that you won’t need to rely on VictoryLegend. That change will be added via https://github.com/patternfly/patternfly-react/pull/3067

I like your use of the onMouseOver and onMouseOut events. While the user hovers over a legend label, the line representing the data series is highlighted by making it 2x wider. Although, that is the opposite behavior I see with PF3.

Kiali UI chrome-capture (2)

In PF3, the opacity is lowered for all other data while hovering over a legend label. That is, we blur everything, but the data series the user is currently viewing.

Considering the Cost Management UI may have up to 8 lines of historical data, we also need a way to hide / show each data series individually. PF3 never implemented that type of behavior.

That said, I took the implementation a little further and was able to mimic some of the PF3 behavior below.

PF3 blur functionality: chrome-capture

I was also able to use onClick events to hide / show each data series individually. Although, I wasn’t able to use events to demo both features at the same time – difficult to ensure events don’t clash and reset the styles of each other.

Hide / Show functionality: chrome-capture (1)

Unfortunately, maintaining state via events doesn’t work very well. When the cursor moves outside the SVG or a tooltip is shown, the hidden data series is redrawn.

This leads me to believe that the hide / show state must be maintained outside the events, similar to my Cost Management example. Charts are stateless and use composition, so I’m not certain we could build that feature internally – may create an example, instead?

That said, I’ve put out the request to our design team to get this prioritized. I’m hoping to use all this as a POC to show what features may be possible.

1reaction
dlabrecqcommented, Oct 4, 2019

I’m going to get some design feedback regarding what we want to implement for react-charts. That is, should we strive to implement the C3 features in PF3 or something completely different, like what Analytics has recently implemented with their legend toggle button?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Legends | FusionCharts
In multi-series charts, you have interactive legends assigned to each set of data. This helps you to relate each and every dataset to...
Read more >
Interactive Legend - Dimple.js
Interactive Legend. The Legend on this chart has been made interactive. It is useful to note the method for orphaning the legend before...
Read more >
Interactive Legend Example | Vega
A scatter plot with interactive guides. Shift-click legend entries to select subsets of the data, or drag along the x-axis to create a...
Read more >
Chart legend - Developer - SEMrush
Chart legend helps a user read the data presented on the chart. Legend items can be controls (checkboxes or radio buttons) or non-interactive...
Read more >
Legend | Chart.js
The chart legend displays data about the datasets that are ... The doughnut, pie, and polar area charts override the legend defaults.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found