How to use Application.ShowChartTipNames in the xlwings API way

The ShowChartTipNames property of the Application object in Excel is a setting that controls whether chart tip names are displayed. Chart tips are the small pop-up labels that appear when you hover the mouse pointer over a chart element, such as a data point, series, or axis title. These tips typically show the name and value of the element. When ShowChartTipNames is set to True, these names are included in the tooltip. When set to False, only the values are shown, if applicable. This property is part of a group of settings that manage on-screen feedback and can be useful for creating cleaner visual presentations or for users who are already familiar with the chart’s data structure and do not require the additional descriptive text.

In the xlwings library, which provides a Pythonic interface to automate and interact with Excel, you access this property through the Application object. The syntax is straightforward, as it is a simple property getter and setter. The property expects a Boolean value (True or False).

xlwings API Syntax:

app = xw.App() # Get the active or a new Excel application instance
# To get the current setting
current_setting = app.api.ShowChartTipNames
# To set the property
app.api.ShowChartTipNames = True # or False

Here, app.api provides direct access to the underlying Excel VBA object model. The ShowChartTipNames property does not take any arguments; it is simply read or written to.

Code Example:
The following example demonstrates how to toggle the ShowChartTipNames setting and verify its state. This can be integrated into a larger script that prepares an Excel environment for a specific reporting task, ensuring that chart tooltips conform to a desired standard.

import xlwings as xw

# Connect to the active Excel instance
with xw.App(visible=True) as app:
# Get the current setting and print it
original_setting = app.api.ShowChartTipNames
print(f"Original ShowChartTipNames setting: {original_setting}")

# Disable the display of names in chart tips
app.api.ShowChartTipNames = False
print("ShowChartTipNames has been set to False. Chart tooltips will now only show values.")

# For demonstration, create a simple chart to see the effect
wb = app.books.add()
sheet = wb.sheets[0]
# Add some sample data
sheet.range('A1').value = [['Category', 'Value'],
['A', 10],
['B', 20],
['C', 15]]
# Create a chart
chart = sheet.charts.add()
chart.set_source_data(sheet.range('A1').expand())
chart.chart_type = 'column_clustered'
chart.api[1].HasTitle = True
chart.api[1].ChartTitle.Text = "Sample Chart"

# Pause to allow user to hover over chart and observe tooltips
input("Hover over a column in the chart. The tooltip should show only the value (e.g., '20'). Press Enter to continue...")

# Re-enable the display of names
app.api.ShowChartTipNames = True
print("ShowChartTipNames has been restored to True. Tooltips will now show names and values.")

input("Hover over a column again. The tooltip should now show both name and value (e.g., 'B: 20'). Press Enter to exit...")

# Optionally, restore the original setting before closing
app.api.ShowChartTipNames = original_setting
wb.close()

July 14, 2026 (0)


Leave a Reply

Your email address will not be published. Required fields are marked *