Configure the display name of a visual data field

This article describes how to get and set the display name of a visual data field that's assigned to a data role. The ability to change display names of visual data fields is useful for visuals that display data field names on reports as column headers. For example, table and matrix visuals.

Get the display name

To get the display name of a visual data field, call the getDataFieldDisplayName method of the visual.

getDataFieldDisplayName(dataRole: string, index: number): Promise<string>

This method has the following variables:

  • dataRole - The name of the target data role to which the data field is assigned.
  • index - The index of the data field whose display name is read.

For example:

let dataFieldDisplayName = visual.getDataFieldDisplayName('Category', 1);

For information about the getDataFields method, see Configure data fields. For information about the getCapabilities method, see Get the capabilities of a visual.

Set the display name

To set the display name of a visual data field, call the setDataFieldDisplayName method of the visual.

setDataFieldDisplayName(dataRole: string, index: number, newDisplayName: string): Promise<IError>

This method has the following variables:

  • dataRole - The name of the target data role to which the data field is assigned.
  • index - The index of the data field whose display name is to be renamed.
  • newDisplayName - The new display name for the data field.

For example:

await visual.setDataFieldDisplayName('Category', 1, 'New Display Name');

Next steps