Skip to content

Data decimation doesn't work. #721

Closed

Description

@hydrognomik

Hi there. Please help, how to make decimation work? I have 500+ points. Decimation works only if I pass redraw prop (or by toggling enabled off and then on in react devtools).

decimation: {
  enabled: true,
  algorithm: 'lttb',
  samples: 12,
  threshold: 12,
},

Activity

  1. mateogianolio commented on Aug 27, 2021

    @mateogianolio

    Same here.. Whatever I do I can't make it work. I have followed the exact steps in chart.js docs (https://www.chartjs.org/docs/latest/configuration/decimation.html).

    I even copied the code from here and ran it to see if any of the if clauses return for my datasets but nope.

  2. mateogianolio commented on Aug 27, 2021

    @mateogianolio

    The dataset object must be mutable. The plugin stores the original data as dataset._data and then defines a new data property on the dataset.

    Because of how react works with immutable props, I believe this is where it fails. If someone has a working example of decimation with this package, do tell :)

  3. self-assigned this
    on Oct 26, 2021
  4. dangreen commented on Oct 26, 2021

    @dangreen
    Collaborator

    @hydrognomik @mateogianolio Hi. Would you please try the latest version of react-chartjs-2?

  5. dangreen commented on Nov 1, 2021

    @dangreen
    Collaborator

    Closed due to inactivity.

  6. lifenouveau commented on Jan 3, 2022

    @lifenouveau

    Still cannot get it to work in v4.0.0
    I got it to work in a sandbox.

  7. aklein24 commented on Jun 7, 2022

    @aklein24

    @lifenouveau Do you have a link to the sandbox? I've been trying hard to get decimation to work without success.

  8. applesin commented on Jul 6, 2022

    @applesin

    Still not working...

  9. emab commented on Sep 1, 2023

    @emab

    A quick fix that seemed to work for me:

    const Chart = (data) => {
      const chart = useRef(chartRef);
      const options = {
        // ...
      };
    
      const datasets = data.map((datum) => {
        // do your mapping here
      });
    
      return (
        <Line
          options={options}
          data={{
            datasets: [...datasets],
          }}
          ref={chartRef}
        />
      );
    };

    The important bit being that you're passing a copy of your datasets to the chart component, rather than something that is contained in the component lifecycle. For me it was enough to use the spread operator.

  10. digiage commented on Sep 29, 2023

    @digiage

    with react-chartjs-2 v5.2.0 the decimation seems to work, but just for lttb. I was not able to make it work with min-max

  11. hpertaia commented on Feb 9, 2024

    @hpertaia

    react-chartjs-2 v5.2.0 with chart.js v4.4.1 lttb decimation isn't working . Error: Сannot destructure property 'x' of 'data[a]' as it is undefined

    Edit: happens only when x scale type is set to time. When set to linear, decimation works.

  12. mhai217 commented on Jun 17, 2024

    @mhai217

    any update?

  13. takuro-kira commented on Dec 23, 2025

    @takuro-kira

    In my case.

    datasets inner data's x is

    Date
    Graph can drawing, but decimation enable cause
    Сannot destructure property 'x' of 'data[a]' as it is undefined error

    epoch time milliseconds
    It's works

    But, some sampling setting value cause same error again.
    I think, In development time, because of small data.
    I can't figure out.

    If it helps someone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions