Skip to content

Hierarchical tooltip configuration definitions #3003

Description

@tiagoroldao

As tooltips are triggered on Elements, a hierarchical callback definition could be made - callbacks are called if defined in (in order of preference):

  • the dataset
  • the axis
  • the chart
  • the chart globals

The reasoning behind this feature is that while creating a complex chart with different needs for label formatting, I found myself doing this a lot:

chartOptions = {
    [...]
    tooltips: {
        callbacks: {
            label: function (tooltip, data) {
                // real implementation accounts for nonexistent object properties
                var datasetCallback = data.datasets[tooltip.datasetIndex].tooltips.callbacks.label;

                if (typeof datasetCallback === 'function') {
                    return datasetCallback(tooltip, data);
                }

                return tooltip.yLabel;
            }
        }
    }
}

Activity

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

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