r9119
r9119

Reputation: 606

Implementing Data Decimation in vue chartjs

I've been trying and failing to implement data decimation in vue chartJS, I'm assuming parsing is the hurdle stopping me as it is the one requirement I cant seem to fulfil.

  1. The dataset must have an indexAxis of 'x'
  2. The dataset must be a line
  3. The X axis for the dataset must be either a 'linear' or 'time' type axis
  4. Data must not need parsing, i.e. parsing must be false
  5. 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.

My current chart options are:

oilOptions: {
    responsive: true,
    scales: {
        y: {
            ... // Formatting and title
        },
        x: {
            type: 'time'
            ... // Formatting and title
        }
    },
    plugins: {
        title: {
            ...
        },
        zoom: {
            ...
        },
        decimation: {
            enabled: true,
            algorithm: 'lttb',
            samples: 500
        }

The dataset is historical Brent oil price data structured like:

{
    labels: [
        "1987-05-20",
        "1987-05-21",
        ...
     ],
     datasets: [
        label: "Brent Oil Price",
        fill: false,
        borderWidth: 2,
        borderColor: "rgb(75, 192, 192)",
        tension: 0.5,
        pointRadius: 0,
        // parsing: false (This stops data from rendering anyway)
        data: [
                18,
                18,
                ...
        ]
     ]

I'm using vue-chartjs but that shouldn't be an issue.

Any help would be appreciated, my other option would be to reduce the data on the backend before passing it to the client, or have a separately saved reduced data set on my DB.

Upvotes: 1

Views: 929

Answers (1)

LeeLenalee
LeeLenalee

Reputation: 31431

No parsing means that you need to provide the data like the internal format so no labels array and objects in your data array like so:

{
  datasets: [{
    label: "Brent Oil Price",
    fill: false,
    borderWidth: 2,
    borderColor: "rgb(75, 192, 192)",
    tension: 0.5,
    pointRadius: 0,
    parsing: false
    data: [{
        x: '1987-05-20',
        y: 5
      },
      {
        x: '1987-05-21',
        y: 6
      }
    ]
  }]
}

The internal data format can be found in the docs here

Upvotes: 2

Related Questions