Skip to content

Feature Request: Expose cubic interpolation algorithm as utility function #12016

Open
@rhlohmeyer

Description

@rhlohmeyer

Feature Proposal

Description:
I'm requesting that Chart.js expose its cubic interpolation algorithm (specifically the 'monotone' mode) as a utility function that developers can use outside of the main chart drawing functionality.

Use Case:
I'm currently developing an application where I need to:

  • Display a main curve using Chart.js's excellent cubic interpolation
  • Show a moving point (date of interest indicator) that should follow the exact same curve
  • Currently, I can only approximate this with linear interpolation between points
  • Having access to the same interpolation algorithm would ensure consistent visualization

Current Workarounds:
Currently, developers needing this functionality must either:

  1. Implement their own cubic interpolation (potentially inconsistent with Chart.js)
  2. Use linear interpolation (less visually appealing)
  3. Create complex workarounds to try to access the internal calculations

Proposed Solution:
Add a utility function to Chart.js that:

  • Takes an array of points (x,y coordinates)
  • Takes a specific x value to interpolate
  • Returns the interpolated y value using the same algorithm as cubicInterpolationMode: 'monotone'

Example API could look like:

const interpolatedY = Chart.helpers.interpolateCubicMonotone(points, xValue);


### Possible Implementation

Proposed Solution:
Add a utility function to Chart.js that:
- Takes an array of points (x,y coordinates)
- Takes a specific x value to interpolate
- Returns the interpolated y value using the same algorithm as cubicInterpolationMode: 'monotone'

Example API could look like:
```javascript
const interpolatedY = Chart.helpers.interpolateCubicMonotone(points, xValue);

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions