Tooltip

Confine tooltip example

ODS Charts library uses the tooltip containment feature of the Apache ECharts library to ensure that the tooltip or popover is displayed within the confines of the graph, avoiding overflow beyond the display window.

This function is activated by configuring the graph options as follows:

tooltip: {
  confine: true,
}
          

Title

Sub-Title
Specific value tooltip content

You may need to specify a specific tooltip content.

The first use case is to provide a sepcific content for a tooltip/popover value.

For that you just have to specify the valueFormatter method of the tooltip Apache Echarts option :

            tooltip: {
              valueFormatter: (value, _dataIndex) =>
                `<span style="color: var(--ods-functional-5); font-size:x-large">${Math.round(value * 100) / 100}</span> °C`,
            },
          

Title

Sub-Title
Other specific content, specific line, with ODS Charts series marker

if you want to specialize more than the value display, you can use the second parameter of the method externalizePopover.

This parameter must implement the ODSChartsPopoverDefinition interface. Generally this is initialized with one of the tooltip managers provided ODSChartsPopoverManagers.BOOSTED5, ODSChartsPopoverManagers.BOOSTED4 or ODSChartsPopoverManagers.NONE.
ODSChartsPopoverManagers.NONE is the default one.

You can extend the tooltip manager to implement one of the ODSChartsPopoverDefinition method.

For example, in the example below, we extend the tooltip manager to implement getPopupContentLine method and return the html code to be displayed for one line:

            themeManager.externalizePopover(undefined, {
              ...ODSCharts.ODSChartsPopoverManagers.NONE,
              getPopupContentLine: ({ seriesName, itemValue, marker }) => {
                return `<p>${marker}This is my HTML code of one line for ${itemValue} of ${seriesName}</p>`;
              },
            });
          

Note: as an alternative, you can still use themeManager.getPopoverMarker(seriesIndex) in your custom renderer.

Prefer using marker from ODSChartsPopoverItem because it is pre-populated with the marker actually used in the tooltip/popover. This is especially useful when item colors override series colors (for example on bar charts). themeManager.getPopoverMarker(seriesIndex) still works, but it is based on the series color.

Title

Sub-Title
Using Boosted 5 tooltip

The same code using the Boosted 5 tooltips:

            themeManager.externalizePopover(undefined, {
              ...ODSCharts.ODSChartsPopoverManagers.BOOSTED5,
              getPopupContentLine: ({ seriesName, itemValue }) => {
                return `<p>This is my HTML code of one line for ${itemValue} of ${seriesName}</p>`;
              },
            });
          

Title

Sub-Title
Tooltip with HTML link(s)

You may need to specify a specific tooltip which include a link.

In this case, you must set to true the parameter enterable of the tooltip Apache Echarts option:

            tooltip: {
              enterable: true,
            },
          

Title

Sub-Title
Using links in a Boosted 5 tooltip

The same code using the Boosted 5 tooltips:

Title

Sub-Title
Custom tooltip template

If you need to completely customize the tooltip template, you can use the getPopupTemplate method.

This method allows you to replace the entire tooltip HTML structure with your own custom template:

            themeManager.externalizePopover(undefined, {
              ...ODSCharts.ODSChartsPopoverManagers.NONE,
              getPopupTemplate: (categoryLabel, tooltipElements) => {
                let content = `<div class="custom-tooltip" style="padding: 12px; background-color: #fff; border: 1px solid #ccc; border-radius: 4px; box-shadow: 0 2px 8px rgba(0,0,0,0.15);">`;
                content += `<h6 class="text-primary" style="font-weight: bold;">${categoryLabel}</h6>`;
                content += `<ul class="list-unstyled mb-0">`;
                tooltipElements.forEach(element => {
                  content += `<li>${element.marker} <strong>${element.seriesName}:</strong> ${element.itemValue}</li>`;
                });
                content += `</ul></div>`;
                return content;
              },
            });
          

Title

Sub-Title
Default Apache ECharts tooltip

This is not the recommended tooltip implementation. When externalizePopover() is not used, the tooltip is rendered by Apache ECharts and only partially follows the Orange Unified Design System. Use externalizePopover() when full OUDS tooltip/popover compliance is required.

ODS Charts can still generate chart options without using externalizePopover(). In this case, Apache ECharts displays its native tooltip using the default tooltip styling provided by the ODS Charts theme.

This use case only calls setDataOptions() and getChartOptions(). No external tooltip or popover manager is registered.

Title

Sub-Title
Default Apache ECharts tooltip with a pie chart

This is not the recommended tooltip implementation. Without externalizePopover(), the native Apache ECharts tooltip only partially follows the Orange Unified Design System. Use externalizePopover() when full OUDS tooltip/popover compliance is required.

This pie chart uses the native Apache ECharts item tooltip. No external tooltip or popover manager is registered.

Title

Sub-Title