swimlane / ngx-charts

:bar_chart: Declarative Charting Framework for Angular
https://swimlane.github.io/ngx-charts/
MIT License
4.29k stars 1.15k forks source link

Hide/Show the corresponding data from the chart on legend click #1131

Open namanpatel6 opened 5 years ago

namanpatel6 commented 5 years ago

I'm submitting a ... (check one with "x")

Current behavior

A legend item on clicking does not hide/show the corresponding data from the chart

Expected behavior

On clicking the legend item, the corresponding data from the chart should show/hide

Reproduction of the problem

What is the motivation / use case for changing the behavior?

Required for projects

Please tell us about your environment:

Windows 10, Angular 7, ngxcharts 10, Chrome

sebastiangug commented 5 years ago

Use Redux and when you click on legend have a function that does something like this: I have this function in my reducer:

function setActiveOffice(
  state: Reporting,
  action: ReportingActions.SetActiveOffice
) {
  if (
    state.activeOfficeSelection.some(
      (office: { name: string }) => office.name === action.office
    )
  ) {
    _.remove(state.activeOfficeSelection, function(el: { name: string }) {
      if (el.name === action.office) {
        return true;
      } else {
        return;
      }
    });
    return tassign(state);
  } else {
    state.activeOfficeSelection.push({ name: action.office });
    return tassign(state);
  }
}

Then use as with | async across all your relevant charts which display the data about the same top-level entities. This is using @ngrx/store

namanpatel6 commented 5 years ago

Any update on this?

medmans commented 5 years ago

There is any update for this feature ?

KingDarBoja commented 5 years ago

@patelnaman6 Did you mean show the same data as onActivate and onDeactivate events? I mean, when you hover over any chart data (bar, line), you get some data insight but if you click on legend, you only get the label name.

medmans commented 5 years ago

@KingDarBoja i think that the goal of this bug is to implement show/hide serie method, if we have two series in the same chart, we can hide one and have still one is showing. isn't it ?

KingDarBoja commented 5 years ago

@KingDarBoja i think that the goal of this bug is to implement show/hide serie method, if we have two series in the same chart, we can hide one and have still one is showing. isn't it ?

Could be possible to do but would require another Input to enable/disable this feature. This could work much like activeEntries one, but instead of highlighting a serie, would be toggling the visibility.

manolait commented 4 years ago

I need this to

manolait commented 4 years ago

Any update on this?

hello, did you manage to solve this problem?

jenswet commented 4 years ago

I'd also need this.

sebastiangug commented 4 years ago

this library has 457 issues opened, I'm pretty sure you're better off implementing your own thing or just going raw with D3

lienok commented 4 years ago

I implemented myself, you can get inspiration here: ngx-multi-bar-chart-click-legend-hide-show-value

manolait commented 4 years ago

Hello, I have already managed to solve the problem adding an example in case it can help other people.

DEMO

Heatmanofurioso commented 2 years ago

This would be quite useful for me on several projects too