Tableau Viz v2 inputSpec
The createVizImageAsync method takes a single argument, the inputSpec, a JavaScript object, and returns the SVG description of that image.
Starting with Tableau 2022.3, you can use version 2 of the inputSpec to create combination charts and dual-axis visualizations.
Version 2 of the inputSpec allows you to specify different mark types for the measures along the encoding axis (either rows or columns).
For versions of Tableau prior to 2022.3, you can use the Tableau Viz v1 inputSpec. The Tableau Viz v1 is supported in Tableau 2021.3 (and later). See the Tableau Viz v1 inputSpec.
The createVizImageAsync method
The createVizImageAsync method is one of the methods in the Tableau Dashboard Extensions API extensions namespace. The method has the following syntax:
createVizImageAsync( inputSpec: *object* ): Promise<string>
This method takes a single argument, the inputSpec, a JavaScript object, and returns the SVG description of that image. To call this method, you first initialize the Dashboard Extensions API (tableau.extensions.initialize()). You then create the inputSpec object that defines your graphic.
For more information about the method, see tableau.extensions.createVizImageAsync in the Dashboard Extensions API reference.
Specification for inputSpec (version 2) object
The inputSpec is a JavaScript object that specifies the name-value pairs to use to create the SVG image. The object consists of the data and the properties that specify how to format the data, for example, vizlayout, columns, rows, encodingaxis and encodings. The data is an array of objects. The data is listed in row-level order, where each object represents one item. The mark property specifies the type of marks to use for the measures on the encoding axis in the image. For example, if you have two continuous fields on the columns shelf, you can specify columns as the encodingaxis and set the marks to different types (bar, line, area, circle, square, or text).
The following shows an example inputSpec that creates a combination chart image that specifies bar and area mark types for the Sales and Profits measures on the columns shelf.
{
version: 2,
description: 'Example Tableau Viz v2',
data: {
values: [
{ Segment: 'Consumer', ShipMode: 'First Class', Category: 'Technology', Profit: 11560.75, Sales: 61089.43 },
{ Segment: 'Corporate', ShipMode: 'First Class', Category: 'Technology', Profit: 7235.75, Sales: 39201.43 },
{ Segment: 'Home Office', ShipMode: 'First Class', Category: 'Technology', Profit: 8706.75, Sales: 39074.43 },
],
},
vizlayout: {
title: 'Example Tableau Viz v2',
},
columns: [
{ field: 'ShipMode', type: tableau.VizImageEncodingType.Discrete },
{ field: 'Sales', type: tableau.VizImageEncodingType.Continuous },
{ field: 'Profit', type: tableau.VizImageEncodingType.Continuous },
],
rows: [{ field: 'Segment', type: tableau.VizImageEncodingType.Discrete }],
encodingaxis: 'columns',
defaultencoding: { mark: tableau.MarkType.Bar },
encodings: [
{
mark: tableau.MarkType.Bar,
},
{
mark: tableau.MarkType.Area,
color: { field: 'Category', type: tableau.VizImageEncodingType.Discrete, palette: { name: 'green_orange_cyan_yellow_10_0' } },
},
],
};
Description of inputSpec (version 2) properties
The following table describes the properties in version 2 of the inputSpec, the JavaScript object that you provide as input to the createVizImageAsync method
version
(Required) Specifies the version of the Tableau Viz. Only used for version 2 and later.
{
version: 2,
// ...
}
description
(Optional) A description about the visualization. Currently, the description is not used anywhere and is not visible when the image is generated. However, it might be helpful to use this description as you comment your code.
description: 'Example description',