Documentation Docs
Documentation Docs

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 to contentContainer.
    • survey: SurveyModel
      Pass a SurveyModel instance 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, seriesValues are used as labels.
  • type: string
    (Optional) The visualizer's type.

View Demo

clear method

Empties the toolbar, header, footer, and content containers.

If you want to empty and delete the visualizer and all its elements from the DOM, call the destroy() method instead.

Type:
() => void
Implemented in:
VisualizerBase
data property

Obsolete. Use surveyData instead.

Type:
any readonly
Implemented in:
VisualizerBase
destroy method

Deletes the visualizer and all its elements from the DOM.

Type:
() => void
Implemented in:
VisualizerBase
See also:
clear
footerVisualizer property

Allows you to access the footer visualizer. Returns undefined if the footer is absent.

Type:
VisualizerBase readonly
Implemented in:
VisualizerBase
See also:
hasFooter

Returns an array of calculated and visualized values. If a user applies a filter, the array is also filtered.

To get an array of source survey results, use the surveyData property.

Type:
() => any
Implemented in:
VisualizerBase
getData method

Obsolete. Use getCalculatedValues() instead.

Type:
() => any
Implemented in:
VisualizerBase
getState method

Returns an object with properties that describe a 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 * , onStateChanged
hasFooter property

Indicates whether the visualizer displays a footer. This property is true when a visualized question has a comment.

Type:
boolean readonly
Implemented in:
VisualizerBase
See also:
hasHeader
hasHeader property

Indicates whether the visualizer displays a header. This property is true when a visualized question has a correct answer.

Type:
boolean readonly
Implemented in:
VisualizerBase
See also:
hasFooter
locale property

Gets or sets the current locale.

If you want to inherit the locale from a visualized survey, assign a SurveyModel instance to the survey property of the IVisualizationPanelOptions object in the VisualizationPanel constructor.

If the survey is translated into more than one language, the toolbar displays a language selection drop-down menu.

Type:
string writable
Implemented in:
VisualizerBase
See also:
onLocaleChanged
name property

Returns the identifier of a visualized question.

Type:
string readonly
Implemented in:
VisualizerBase

An event that is raised after the visualizer's content is rendered.

Parameters:

  • sender: VisualizerBase
    A VisualizerBase instance that raised the event.

  • options.htmlElement: HTMLElement
    A page element with the visualizer's content.

Type:
Event<(sender: VisualizerBase, options: any) => any, VisualizerBase, any>
Implemented in:
VisualizerBase
See also:
render * , refresh **

An event that is raised after a new locale is set.

Parameters:

  • sender: VisualizerBase
    A VisualizerBase instance that raised the event.

  • 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

An event that is raised when the visualizer's state has changed.

The state includes selected chart types, chart layout, sorting, filtering, and other customizations that a user has made while using the dashboard. Handle the onStateChanged event to save these customizations, for example, in localStorage and restore them when the user reloads the page.

Parameters:

  • sender: VisualizerBase
    A VisualizerBase instance that raised the event.

  • state: any
    A new state of the visualizer. Includes information about the visualized elements and current locale.

View Demo

Type:
Event<(sender: VisualizerBase, options: any) => any, VisualizerBase, any>
Implemented in:
VisualizerBase
See also:
getState * , setState
refresh method

Re-renders the visualizer and its content.

Type:
() => void
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?: HTMLDivElement) => HTMLElement) => void
Parameters:
name, type: string ,

A custom name for the toolbar item.

creator, type: (toolbar?: HTMLDivElement) => HTMLElement ,

A function that accepts the toolbar and should return an HTMLElement with the toolbar item.

Implemented in:
VisualizerBase
See also:
unregisterToolbarItem
render method

Renders the visualizer in a specified container.

Type:
(targetElement: string | HTMLElement) => void
Parameters:
targetElement, type: string | HTMLElement ,

An HTMLElement or an id of a page element in which you want to render the visualizer.

Implemented in:
VisualizerBase
setState method

Sets the visualizer's state.

This method is overriden in classes descendant from VisualizerBase.

Type:
(state: any) => void
Parameters:
state, type: any
Implemented in:
VisualizerBase
See also:
getState * , onStateChanged
showToolbar property

Gets or sets the visibility of the visualizer's toolbar.

Default value: true

Type:
boolean writable
Implemented in:
VisualizerBase
supportSelection property

Indicates whether users can select series points to cross-filter charts. To allow or disallow selection, set the allowSelection property of the IVisualizationPanelOptions object in the VisualizationPanel constructor.

Type:
boolean readonly
Implemented in:
VisualizerBase
surveyData property

Returns an array of survey results used to calculate values for visualization. If a user applies a filter, the array is also filtered.

To get an array of calculated and visualized values, call the getCalculatedValues() method.

Type:
any readonly
Implemented in:
VisualizerBase
type property

Returns the visualizer's type.

Type:
string readonly
Implemented in:
VisualizerBase

Unregisters a function used to create a toolbar item. Allows you to remove a toolbar item.

Type:
(name: string) => (toolbar?: HTMLDivElement) => HTMLElement
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
updateData method

Updates visualized data.

Type:
(data: any) => void
Parameters:
data, type: any ,

A data array with survey results to be visualized.

Implemented in:
VisualizerBase

Copyright © 2024 Devsoft Baltic OÜ. All rights reserved.

Your cookie settings

We use cookies on our site to make your browsing experience more convenient and personal. In some cases, they are essential to making the site work properly. By clicking "Accept All", you consent to the use of all cookies in accordance with our Terms of Use & Privacy Statement. However, you may visit "Cookie settings" to provide a controlled consent.

Your renewal subscription expires soon.

Since the license is perpetual, you will still have permanent access to the product versions released within the first 12 month of the original purchase date.

If you wish to continue receiving technical support from our Help Desk specialists and maintain access to the latest product updates, make sure to renew your subscription by clicking the "Renew" button below.

Your renewal subscription has expired.

Since the license is perpetual, you will still have permanent access to the product versions released within the first 12 month of the original purchase date.

If you wish to continue receiving technical support from our Help Desk specialists and maintain access to the latest product updates, make sure to renew your subscription by clicking the "Renew" button below.