For AI agents: a documentation index is available at https://www.mongodb.com/docs/llms.txt — markdown versions of all pages are available by appending .md to any URL path.
Make the MongoDB docs better! We value your opinion. Share your feedback for a chance to win $100.
MongoDB Branding Shape
Click here >
Docs Menu

Highlight Chart Elements

The Charts Embedding JavaScript SDK enables you to programmatically highlight specific elements and clicked events on embedded charts and charts within embedded dashboards.

Before you begin, install version 2.1.0 or later of the Charts Embedding JavaScript SDK.

The Charts Embedding JavaScript SDK method for enabling highlighting has the following syntax:

charts.setHighlight(selectionFilter);

Note

If you want to highlight charts within an embedded dashboard, first run the following method to retrieve a specific chart from the Dashboard instance:

dashboard.getChart('<chartID>');

The setHighlight method takes an filter. You can provide the MQL filter directly to the setHighlight method as shown in the example below or through the click event payload selectionFilter to highlight specific elements and click events.

Example

chart.setHighlight(
{
city: { $nin: ['New York', 'London', 'Paris'] }
}
)

The selectionFilter must match on values used on the chart's category or series channel.

The Charts Embedding JavaScript SDK also includes the highlight option for retrieving the highlight query:

const highlight = chart.getHighlight();

The highlight option takes a parameter of a Javascript object that represents an filter. You can set the highlight option when you create a chart or after a chart renders.

You can include the following query elements:

The following chart types support programmatic highlighting: