VisualizerBase
A base object for all visualizers. Use it to implement a custom visualizer.
Constructor parameters:
question:Question
A survey question to visualize.data:Array<any>
Survey results.options
An object with the following properties:dataProvider:DataProvider
A data provider for this visualizer.renderContent:(contentContainer: HTMLElement, visualizer: VisualizerBase) => void
A function that renders the visualizer's HTML markup. Append the markup tocontentContainer.survey:SurveyModel
Pass aSurveyModelinstance if you want to use locales from the survey JSON schema.seriesValues:Array<string>
Series values used to group data.seriesLabels:Array<string>
Series labels to display. If this property is not set,seriesValuesare used as labels.
type:string
(Optional) The visualizer's type.
Properties
Methods
Applies a theme to the Dashboard.
- Type:
- (theme: ITheme, baseTheme?: ITheme) => void
- Parameters:
-
baseTheme, type: ITheme ,
An optional
IThemeobject used as the base theme. When specified, it is deep-merged withtheme, and the merged result is applied.
- Implemented in:
- VisualizerBase
Clears the toolbar, header, content, and footer containers and removes the license banner and visualizer wrapper from the root.
Does not remove the visualizer root element from the DOM. Use destroy() to fully dispose of the visualizer.
- Type:
- () => void
- Implemented in:
- VisualizerBase
Deletes the visualizer and removes its DOM elements.
- Type:
- () => void
- Implemented in:
- VisualizerBase
- See also:
- clear
Returns calculated values used for visualization. If a user applies a filter, the array is also filtered.
To access an array of source survey results, use the surveyData property.
- Type:
- () => Promise<ICalculationResult<number>>
- Implemented in:
- VisualizerBase
Returns an object with properties that describe the current visualizer state. The properties are different for each individual visualizer.
This method is overriden in classes descendant from
VisualizerBase.
- Type:
- () => any
- Implemented in:
- VisualizerBase
- See also:
- setState * , resetState * , onStateChanged *
Indicates whether the visualizer renders a header. Returns true if the question defines a correctAnswer.
- Type:
- boolean readonly
- Implemented in:
- VisualizerBase
- See also:
- hasFooter *
Gets or sets the current locale.
If you want to inherit the locale from a visualized survey, assign a SurveyModel instance to the survey option passed to the Dashboard.
If the survey is translated into more than one language, the dashboard toolbar displays a language selection drop-down menu.
- Type:
- string writable
- Implemented in:
- VisualizerBase
- See also:
- onLocaleChanged
Returns the identifier of a visualized question.
- Type:
- string readonly
- Implemented in:
- VisualizerBase
Raised after the visualizer content is rendered.
Parameters:
sender:VisualizerBase
The currentVisualizerBaseinstance.options.htmlElement:HTMLElement
AnHTMLElementthat contains the rendered content.
- Type:
- Event<(sender: VisualizerBase, options: any) => any, VisualizerBase, any>
- Implemented in:
- VisualizerBase
Raised after the locale changes.
Parameters:
sender:VisualizerBase
The currentVisualizerBaseinstance.options.locale:string
The indentifier of a new locale (for example,"en").
- Type:
- Event<(sender: VisualizerBase, options: { locale: string; }) => any, VisualizerBase, any>
- Implemented in:
- VisualizerBase
- See also:
- locale
Raised when the visualizer state changes.
The state contains user-defined settings such as selected chart type, layout, sorting, filtering, and other runtime customizations. Handle this event to persist these customizations (for example, in localStorage) and restore them later.
Parameters:
sender:VisualizerBase
The currentVisualizerBaseinstance.state:any
The new state of the visualizer.
- Type:
- Event<(sender: VisualizerBase, options: any) => any, VisualizerBase, any>
- Implemented in:
- VisualizerBase
Registers a function used to create a toolbar item for this visualizer.
The following code shows how to add a custom button and drop-down menu to the toolbar:
import { VisualizationPanel, DocumentHelper } from "survey-analytics";
const vizPanel = new VisualizationPanel( ... );
// Add a custom button to the toolbar
vizPanel.visualizers[0].registerToolbarItem("my-toolbar-button", () => {
return DocumentHelper.createButton(
// A button click event handler
() => {
alert("Custom toolbar button is clicked");
},
// Button caption
"Button"
);
});
// Add a custom drop-down menu to the toolbar
vizPanel.visualizers[0].registerToolbarItem("my-toolbar-dropdown", () => {
return DocumentHelper.createSelector(
// Menu items
[
{ value: 1, text: "One" },
{ value: 2, text: "Two" },
{ value: 3, text: "Three" }
],
// A function that specifies initial selection
(option) => false,
// An event handler that is executed when selection is changed
(e) => {
alert(e.target.value);
}
);
});
- Type:
- (name: string, creator: (toolbar?: any) => any, type: ToolbarItemType, index?: number, groupIndex?: number) => void
- Parameters:
-
name, type: string ,
A custom name for the toolbar item.
creator, type: (toolbar?: any) => any ,A function that accepts the toolbar and should return an
HTMLElementwith the toolbar item.type, type: "dropdown" | "button" | "filter" | "license"index, type: numbergroupIndex, type: number
- Implemented in:
- VisualizerBase
- See also:
- unregisterToolbarItem *
Renders the visualizer inside a specified container.
- Type:
- (targetElement: any, isRoot?: boolean) => void
- Parameters:
-
targetElement, type: any ,
An
HTMLElementor theidof a DOM element.isRoot, type: boolean
- Implemented in:
- VisualizerBase
Resets the visualizer state.
This method is overriden in classes descendant from
VisualizerBase.
- Type:
- () => void
- Implemented in:
- VisualizerBase
- See also:
- getState * , setState * , onStateChanged *
Sets the visualizer state.
This method is overriden in classes descendant from
VisualizerBase.
- Type:
- (state: any) => void
- Parameters:
-
state, type: any
- Implemented in:
- VisualizerBase
- See also:
- getState * , resetState * , onStateChanged *
Gets or sets whether the toolbar is visible.
Default value: true
- Type:
- boolean writable
- Implemented in:
- VisualizerBase
Indicates whether users can select chart elements to apply cross-filtering. Controlled by the allowSelection option passed to the Dashboard.
- Type:
- boolean readonly
- Implemented in:
- VisualizerBase
Returns an array of survey result objects used to calculate values for visualization. If a user applies a filter, the array is also filtered.
To obtain calculated values, call getCalculatedValues().
- Type:
- any[] readonly
- Implemented in:
- VisualizerBase
Unregisters a function used to create a toolbar item. Allows you to remove a toolbar item.
- Type:
- (name: string) => (toolbar?: any) => any
- Parameters:
-
name, type: string ,
A toolbar item name.
- Return Value:
-
A function previously used to register the removed toolbar item.
- Implemented in:
- VisualizerBase
- See also:
- registerToolbarItem *
Updates the visualized data.
- Type:
- (data: GetDataFn | { [index: string]: any; }[]) => void
- Parameters:
-
data, type: GetDataFn | { [index: string]: any; }[] ,
An array of survey result objects or a data-loading function.
- Implemented in:
- VisualizerBase
Send feedback to the SurveyJS team
Need help? Visit our support page