### Run test examples with npm run serve Source: https://github.com/surveyjs/survey-analytics/blob/master/README.md Starts a local HTTP server at http://localhost:8080/ to run test examples. Demos are located in examples/chart.js, examples/apexcharts, and examples (Plotly). ```sh npm run serve ``` -------------------------------- ### Full Code Example for Manual Dashboard Configuration Source: https://github.com/surveyjs/survey-analytics/blob/master/docs/get-started-react.md Complete example showing font imports, CSS import, survey JSON, survey results, and the Dashboard component with manual items configuration. Includes the necessary imports and setup for a React app. ```js // app/layout.tsx or pages/_app.tsx import '@fontsource/open-sans/400.css'; import '@fontsource/open-sans/600.css'; import '@fontsource/open-sans/700.css'; ``` ```js // components/Dashboard.tsx import 'survey-analytics/survey.analytics.css'; import { useState } from 'react'; import { Model } from 'survey-core'; import { IDashboardOptions, Dashboard } from 'survey-analytics'; const surveyJson = { elements: [{ name: "satisfaction-score", title: "How would you describe your experience with our product?", type: "radiogroup", choices: [ { value: 5, text: "Fully satisfying" }, { value: 4, text: "Generally satisfying" }, { value: 3, text: "Neutral" }, { value: 2, text: "Rather unsatisfying" }, { value: 1, text: "Not satisfying at all" } ], isRequired: true }, { name: "nps-score", title: "On a scale of zero to ten, how likely are you to recommend our product to a friend or colleague?", type: "rating", rateMin: 0, rateMax: 10, }], completedHtml: "Thank you for your feedback!", }; const surveyResults = [ { "satisfaction-score": 5, "nps-score": 10 }, { "satisfaction-score": 5, "nps-score": 9 }, { "satisfaction-score": 3, "nps-score": 6 }, { "satisfaction-score": 3, "nps-score": 6 }, { "satisfaction-score": 2, "nps-score": 3 } ]; export default function DashboardComponent() { const [dashboard, setDashboard] = useState(null); useEffect(() => { const survey = new Model(surveyJson); const dashboardInstance = new Dashboard({ data: surveyResults, items: [ { name: "satisfaction-score", type: "bar", title: "CSAT", availableTypes: [ "bar", "vbar", "pie", "gauge" ] }, { name: "nps-score", type: "nps", title: "NPS Score", allowChangeType: false } ] }); setDashboard(dashboardInstance); }, []); return "..."; } ``` -------------------------------- ### Full Angular dashboard setup with survey model and results Source: https://github.com/surveyjs/survey-analytics/blob/master/docs/get-started-angular.md Complete example combining the template container, survey model, survey results, and Dashboard configuration. The dashboard renders in the 'dashboard' div after the view initializes. ```html
``` ```js import { AfterViewInit, Component } from '@angular/core'; import { Model } from 'survey-core'; import { Dashboard } from 'survey-analytics'; const surveyJson = { elements: [{ name: "satisfaction-score", title: "How would you describe your experience with our product?", type: "radiogroup", choices: [ { value: 5, text: "Fully satisfying" }, { value: 4, text: "Generally satisfying" }, { value: 3, text: "Neutral" }, { value: 2, text: "Rather unsatisfying" }, { value: 1, text: "Not satisfying at all" } ], isRequired: true }, { name: "nps-score", title: "On a scale of zero to ten, how likely are you to recommend our product to a friend or colleague?", type: "rating", rateMin: 0, rateMax: 10, }], completedHtml: "Thank you for your feedback!", }; const surveyResults = [ { "satisfaction-score": 5, "nps-score": 10 }, { "satisfaction-score": 5, "nps-score": 9 }, { "satisfaction-score": 3, "nps-score": 6 }, { "satisfaction-score": 3, "nps-score": 6 }, { "satisfaction-score": 2, "nps-score": 3 } ]; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent implements AfterViewInit { title = 'SurveyJS Dashboard for Angular'; ngAfterViewInit(): void { const survey = new Model(surveyJson); const dashboard = new Dashboard({ questions: survey.getAllQuestions(), data: surveyResults, items: [ "satisfaction-score", { name: "nps-score", type: "nps" } ] }); dashboard.render("dashboard"); } } ``` -------------------------------- ### Install dependencies with npm install Source: https://github.com/surveyjs/survey-analytics/blob/master/README.md Installs project dependencies. Requires survey-core to be built first because package.json points survey-core at ../survey-library/packages/survey-core/build. ```sh npm install ``` -------------------------------- ### Full Angular Table View Example Source: https://github.com/surveyjs/survey-analytics/blob/master/docs/set-up-table-view-angular.md Complete example showing the Angular component template and TypeScript code to set up the Table View with Tabulator, including survey JSON, data generation, and rendering. ```html
``` ```typescript import { AfterViewInit, Component } from '@angular/core'; import { Model } from 'survey-core'; import { Tabulator } from 'survey-analytics/survey.analytics.tabulator'; const surveyJson = { elements: [{ name: "satisfaction-score", title: "How would you describe your experience with our product?", type: "radiogroup", choices: [ { value: 5, text: "Fully satisfying" }, { value: 4, text: "Generally satisfying" }, { value: 3, text: "Neutral" }, { value: 2, text: "Rather unsatisfying" }, { value: 1, text: "Not satisfying at all" } ], isRequired: true }, { name: "nps-score", title: "On a scale of zero to ten, how likely are you to recommend our product to a friend or colleague?", type: "rating", rateMin: 0, rateMax: 10, }], completedHtml: "Thank you for your feedback!", }; function randomIntFromInterval(min: number, max: number): number { return Math.floor(Math.random() * (max - min + 1) + min); } function generateData() { const data = []; for (let index = 0; index < 100; index++) { const satisfactionScore = randomIntFromInterval(1, 5); const npsScore = satisfactionScore > 3 ? randomIntFromInterval(7, 10) : randomIntFromInterval(1, 6); data.push({ "satisfaction-score": satisfactionScore, "nps-score": npsScore }); } return data; } @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent implements AfterViewInit { ngAfterViewInit(): void { const survey = new Model(surveyJson); const surveyDataTable = new Tabulator( survey, generateData() ); surveyDataTable.render("surveyDataTable"); } } ``` -------------------------------- ### Full code for dashboard configuration Source: https://github.com/surveyjs/survey-analytics/blob/master/docs/get-started-react.md Complete example including font imports, CSS import, survey JSON, results, and dashboard setup. The survey JSON defines two questions: satisfaction-score and nps-score. The dashboard uses getAllQuestions() and items array to set NPS type. ```js // app/layout.tsx or pages/_app.tsx import '@fontsource/open-sans/400.css'; import '@fontsource/open-sans/600.css'; import '@fontsource/open-sans/700.css'; ``` ```js // components/Dashboard.tsx import 'survey-analytics/survey.analytics.css'; import { useState } from 'react'; import { Model } from 'survey-core'; import { IDashboardOptions, Dashboard } from 'survey-analytics'; const surveyJson = { elements: [{ name: "satisfaction-score", title: "How would you describe your experience with our product?", type: "radiogroup", choices: [ { value: 5, text: "Fully satisfying" }, { value: 4, text: "Generally satisfying" }, { value: 3, text: "Neutral" }, { value: 2, text: "Rather unsatisfying" }, { value: 1, text: "Not satisfying at all" } ], isRequired: true }, { name: "nps-score", title: "On a scale of zero to ten, how likely are you to recommend our product to a friend or colleague?", type: "rating", rateMin: 0, rateMax: 10, }], completedHtml: "Thank you for your feedback!", }; const surveyResults = [ { "satisfaction-score": 5, "nps-score": 10 }, { "satisfaction-score": 5, "nps-score": 9 }, { "satisfaction-score": 3, "nps-score": 6 }, { "satisfaction-score": 3, "nps-score": 6 }, { "satisfaction-score": 2, "nps-score": 3 } ]; export default function DashboardComponent() { const [dashboard, setDashboard] = useState(null); useEffect(() => { const survey = new Model(surveyJson); const dashboardInstance = new Dashboard({ questions: survey.getAllQuestions(), data: surveyResults, items: [ "satisfaction-score", { name: "nps-score", type: "nps" } ] }); setDashboard(dashboardInstance); }, []); return "..."; } ``` -------------------------------- ### Install survey-analytics via npm Source: https://github.com/surveyjs/survey-analytics/blob/master/README.md Install the survey-analytics package. survey-core is a peer dependency; if not already installed, install both packages together. ```sh npm install survey-analytics ``` ```sh npm install survey-core survey-analytics ``` -------------------------------- ### Full Angular Dashboard Configuration Example Source: https://github.com/surveyjs/survey-analytics/blob/master/docs/get-started-angular.md Complete example of configuring the Dashboard in Angular with survey JSON, results, and items array. The survey includes a radiogroup for satisfaction score and a rating for NPS score. The dashboard is created in ngAfterViewInit with auto-generated questions and custom item configuration. ```JavaScript import { AfterViewInit, Component } from '@angular/core'; import { Model } from 'survey-core'; import { Dashboard } from 'survey-analytics'; const surveyJson = { elements: [{ name: "satisfaction-score", title: "How would you describe your experience with our product?", type: "radiogroup", choices: [ { value: 5, text: "Fully satisfying" }, { value: 4, text: "Generally satisfying" }, { value: 3, text: "Neutral" }, { value: 2, text: "Rather unsatisfying" }, { value: 1, text: "Not satisfying at all" } ], isRequired: true }, { name: "nps-score", title: "On a scale of zero to ten, how likely are you to recommend our product to a friend or colleague?", type: "rating", rateMin: 0, rateMax: 10, }], completedHtml: "Thank you for your feedback!", }; const surveyResults = [ { "satisfaction-score": 5, "nps-score": 10 }, { "satisfaction-score": 5, "nps-score": 9 }, { "satisfaction-score": 3, "nps-score": 6 }, { "satisfaction-score": 3, "nps-score": 6 }, { "satisfaction-score": 2, "nps-score": 3 } ]; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent implements AfterViewInit { title = 'SurveyJS Dashboard for Angular'; ngAfterViewInit(): void { const survey = new Model(surveyJson); const dashboard = new Dashboard({ questions: survey.getAllQuestions(), data: surveyResults, items: [ "satisfaction-score", { name: "nps-score", type: "nps" } ] }); } } ``` -------------------------------- ### start(container) Source: https://github.com/surveyjs/survey-analytics/blob/master/docs/api-reference/layoutengine.md Enables the dynamic layout in a given HTML element. This method should arrange visualization items based on the available screen space and allow users to reorder them via drag and drop. ```APIDOC ## start(container) ### Description Enables the dynamic layout in a given HTML element. This method should arrange visualization items based on the available screen space and allow users to reorder them via drag and drop. ### Method start ### Parameters - **container** (HTMLElement) - Required - The HTML element in which the dynamic layout is enabled. ### Available Since v3.0.0 ``` -------------------------------- ### Install Open Sans font package Source: https://github.com/surveyjs/survey-analytics/blob/master/docs/get-started-angular.md Install the @fontsource/open-sans package to load Open Sans fonts, required since SurveyJS v3.0.4 no longer includes fonts. ```sh npm install @fontsource/open-sans ``` -------------------------------- ### Install jsPDF, jsPDF-AutoTable, and SheetJS libraries Source: https://github.com/surveyjs/survey-analytics/blob/master/docs/set-up-table-view-angular.md Run these npm commands to install the third-party libraries required for PDF and Excel export in Table View. jsPDF 2.4.0 or later, jsPDF-AutoTable 3.5.20 or later, and SheetJS 0.18.5 or later are required. ```sh npm i jspdf npm i jspdf-autotable npm i xlsx ``` -------------------------------- ### Full code for setting up Table View in Vue Source: https://github.com/surveyjs/survey-analytics/blob/master/docs/set-up-table-view-vue.md Complete example including stylesheet imports, survey JSON definition, data generation, and rendering. The survey includes a radiogroup and a rating question, and generates 100 random responses. ```ts // main.ts import '@fontsource/open-sans/400.css'; import '@fontsource/open-sans/600.css'; import '@fontsource/open-sans/700.css'; ``` ```html ``` -------------------------------- ### Run end-to-end and accessibility tests with Playwright Source: https://github.com/surveyjs/survey-analytics/blob/master/README.md Runs E2E, visual-regression, and accessibility tests using Playwright. Do not start an HTTP server manually; the Playwright config starts its own. Includes commands for all charting engines, a single engine, a single test, and accessibility tests. ```sh npm run e2e:ci # all charting engines npm run e2e:ci:chartjs # a single engine npm run e2e:ci -- --grep "TestName" # a single test npm run accessibility-tests:ci # accessibility ``` -------------------------------- ### Install survey-analytics npm package Source: https://github.com/surveyjs/survey-analytics/blob/master/docs/get-started-angular.md Install the SurveyJS Dashboard package for Angular. The Chart.js dependency is installed automatically. ```sh npm install survey-analytics ``` -------------------------------- ### E2E / VRT Commands (Playwright) Source: https://github.com/surveyjs/survey-analytics/blob/master/CLAUDE.md Run Playwright tests in CI with chromium project, interactive UI mode, or filter by test name with --grep. playwright.config.ts starts its own web server (npm run start → http-server on http://localhost:8080) — do not pre-start one. Specs in e2e/ carry *-snapshots/ directories for visual regression. ```bash npm run e2e:ci # playwright test --project chromium ``` ```bash npm run e2e # interactive UI mode ``` ```bash npm run e2e:ci -- --grep "TestName" ``` -------------------------------- ### Create a custom locale Source: https://github.com/surveyjs/survey-analytics/blob/master/docs/localization.md Register a custom locale with `setupLocale` to change several captions or translate controls into a new language. This example registers a custom English locale with two changed captions. Keep the dictionary in a separate file and import it before rendering. ```JavaScript // custom-locale.js import { setupLocale } from "survey-analytics"; const customLocaleStrings = { resetFilter: "Clear filters", chartType_bar: "Bar chart" }; setupLocale({ localeCode: "en-custom", strings: customLocaleStrings, nativeName: "Custom English" }); ``` ```JavaScript import "./custom-locale.js"; dashboard.locale = "en-custom"; ``` -------------------------------- ### Install survey-analytics and Plotly.js type definitions (Angular) Source: https://github.com/surveyjs/survey-analytics/blob/master/docs/integration-with-plotlyjs.md Install the survey-analytics npm package and the Plotly.js type definitions for Angular projects. ```sh npm install survey-analytics npm i @types/plotly.js-dist-min-dev ``` -------------------------------- ### Enable localization and select a locale Source: https://github.com/surveyjs/survey-analytics/blob/master/docs/localization.md Assign a locale code to the `locale` property to apply a built-in language. This example applies French. Set `dashboard.locale` before rendering to change built-in control text. ```JavaScript import { Dashboard } from "survey-analytics"; const dashboard = new Dashboard({ questions: surveyQuestions, data: surveyResults }); dashboard.locale = "fr"; dashboard.render("dashboardContainer"); ``` -------------------------------- ### Full Vue code for Survey Analytics dashboard Source: https://github.com/surveyjs/survey-analytics/blob/master/docs/get-started-vue.md Complete example showing imports, survey JSON, results data, and dashboard configuration. Requires importing 'survey-analytics/survey.analytics.css' and fontsource CSS. The dashboard renders into the 'dashboard' div on mount. ```ts // main.ts import '@fontsource/open-sans/400.css'; import '@fontsource/open-sans/600.css'; import '@fontsource/open-sans/700.css'; ``` ```html ``` -------------------------------- ### showToolbar Source: https://github.com/surveyjs/survey-analytics/blob/master/docs/api-reference/visualizerbase.md Gets or sets whether the toolbar is visible. Default value is `true`. ```APIDOC ## Property: showToolbar ### Description Gets or sets whether the toolbar is visible. Default value is `true`. ### Type `boolean` ``` -------------------------------- ### Configure Tabulator with jsPDF and SheetJS for export Source: https://github.com/surveyjs/survey-analytics/blob/master/docs/set-up-table-view-vue.md Import a jsPDF instance, apply the jsPDF-AutoTable plugin, import SheetJS, and pass both instances to the Tabulator constructor to enable PDF and Excel export. The snippet shows the required imports and setup inside a Vue component's onMounted hook. ```html ``` -------------------------------- ### Import Tabulator and Table View styles in Vue component Source: https://github.com/surveyjs/survey-analytics/blob/master/docs/set-up-table-view-vue.md Add these imports in the component that renders the Table View. The script setup block imports the required CSS files. ```html ``` -------------------------------- ### Configure Dashboard Items Manually (Vue script setup) Source: https://github.com/surveyjs/survey-analytics/blob/master/docs/get-started-vue.md Populate the `items` array with `IDashboardItemOptions` objects and use the `name` property to bind each item to a data field. This snippet shows the core configuration inside a Vue component's `onMounted` hook. ```html ``` -------------------------------- ### Manual Dashboard Configuration with Items Array Source: https://github.com/surveyjs/survey-analytics/blob/master/docs/get-started-react.md Configure dashboard items manually when not based on a survey schema. Populate the items array with IDashboardItemOptions objects and use the name property to bind each item to a data field. The example shows a bar chart for satisfaction-score and an NPS chart for nps-score. ```js // components/Dashboard.tsx // ... import { useEffect, useState } from 'react'; import { Model } from 'survey-core'; import { Dashboard } from 'survey-analytics'; const SURVEY_ID = 1; const surveyJson = { /* ... */ }; const surveyResults = [ /* ... */ ]; export default function DashboardComponent() { const [dashboard, setDashboard] = useState(null); useEffect(() => { const survey = new Model(surveyJson); const dashboardInstance = new Dashboard({ data: surveyResults, items: [ { name: "satisfaction-score", type: "bar", title: "CSAT", availableTypes: [ "bar", "vbar", "pie", "gauge" ] }, { name: "nps-score", type: "nps", title: "NPS Score", allowChangeType: false } ] }); setDashboard(dashboardInstance); }, []); return "..."; } ``` -------------------------------- ### Full Code Example: HTML and JavaScript Source: https://github.com/surveyjs/survey-analytics/blob/master/docs/get-started-html-css-javascript.md Complete HTML page that loads SurveyJS Dashboard and Chart.js, and a JavaScript file that creates a dashboard with manually configured items. The HTML includes the necessary script and style links, and the JavaScript defines sample survey results and the dashboard configuration. ```html SurveyJS Dashboard ``` ```js const surveyResults = [ { "satisfaction-score": 5, "nps-score": 10 }, { "satisfaction-score": 5, "nps-score": 9 }, { "satisfaction-score": 3, "nps-score": 6 }, { "satisfaction-score": 3, "nps-score": 6 }, { "satisfaction-score": 2, "nps-score": 3 } ]; const dashboard = new SurveyAnalytics.Dashboard({ data: surveyResults, items: [ { name: "satisfaction-score", type: "bar", title: "CSAT", availableTypes: [ "bar", "vbar", "pie", "gauge" ] }, { name: "nps-score", type: "nps", title: "NPS Score", allowChangeType: false } ] }); ``` -------------------------------- ### Full code for Vue dashboard with items array Source: https://github.com/surveyjs/survey-analytics/blob/master/docs/get-started-vue.md Complete example including imports, survey JSON, results, and dashboard configuration. The items array sets the default NPS visualization type for the nps-score question. ```ts // main.ts import '@fontsource/open-sans/400.css'; import '@fontsource/open-sans/600.css'; import '@fontsource/open-sans/700.css'; ``` ```html ``` -------------------------------- ### Create flattened checkbox tabulator with splitMultiSelectIntoColumns Source: https://github.com/surveyjs/survey-analytics/blob/master/examples/flattened-checkbox.html Defines a survey with a checkbox question and sample data, then creates three Tabulator instances: one with splitMultiSelectIntoColumns: true (default checkmark mode), one with multiSelectColumnValueFormat: 'selectionOrder', and one with splitMultiSelectIntoColumns: false for comparison. Each instance is rendered into a separate container. ```javascript // Define the survey JSON var json = { elements: [ { type: "checkbox", name: "fav_cars", title: "Favorite Cars", choices: [ { value: "car1", text: "Car 1" }, { value: "car2", text: "Car 2" }, { value: "car3", text: "Car 3" } ] }, { type: "text", name: "name", title: "Name" } ] }; // Sample data var data = [ { fav_cars: ["car1", "car2"], name: "John Doe" }, { fav_cars: ["car2"], name: "Jane Smith" }, { fav_cars: ["car1", "car3"], name: "Bob Johnson" }, { fav_cars: [], name: "Alice Williams" } ]; var survey = new Survey.SurveyModel(json); // Create flattened checkbox tabulator with checkmarks (default) var surveyAnalyticsFlattenedTabulator = new SurveyAnalyticsTabulator.Tabulator( survey, data, { splitMultiSelectIntoColumns: true } ); surveyAnalyticsFlattenedTabulator.render("tabulatorFlattenedContainer"); // Create flattened checkbox tabulator with selection order var surveyAnalyticsOrderTabulator = new SurveyAnalyticsTabulator.Tabulator( survey, data, { splitMultiSelectIntoColumns: true, multiSelectColumnValueFormat: "selectionOrder" } ); surveyAnalyticsOrderTabulator.render("tabulatorOrderContainer"); // Create normal tabulator for comparison var surveyAnalyticsNormalTabulator = new SurveyAnalyticsTabulator.Tabulator( survey, data, { splitMultiSelectIntoColumns: false } ); surveyAnalyticsNormalTabulator.render("tabulatorNormalContainer"); ``` -------------------------------- ### Render VisualizationPanel with Large Values Source: https://github.com/surveyjs/survey-analytics/blob/master/examples/chart.js/large-values.html Creates a SurveyModel from JSON, builds a VisualizationPanel for all survey questions with the provided data, enables the toolbar, and renders it into the summaryContainer element. Use this snippet to display analytics visualizations for large datasets. ```JavaScript var survey = new Survey.SurveyModel(json); var visPanel = new SurveyAnalytics.VisualizationPanel( survey.getAllQuestions(), data, {} ); visPanel.showToolbar = true; visPanel.render(document.getElementById("summaryContainer")); ``` -------------------------------- ### Full Code: Font imports, Dashboard component, and Next.js page Source: https://github.com/surveyjs/survey-analytics/blob/master/docs/get-started-react.md Complete setup for the SurveyJS Analytics dashboard in React. Includes Open Sans font imports, the Dashboard component with survey model and results, and the Next.js page using dynamic import with ssr: false. The component renders the dashboard and cleans up on unmount. ```js // app/layout.tsx or pages/_app.tsx import '@fontsource/open-sans/400.css'; import '@fontsource/open-sans/600.css'; import '@fontsource/open-sans/700.css'; ``` ```js // components/Dashboard.tsx 'use client' import { useState, useEffect } from 'react'; import 'survey-analytics/survey.analytics.css'; import { Model } from 'survey-core'; import { Dashboard } from 'survey-analytics'; const surveyJson = { elements: [{ name: "satisfaction-score", title: "How would you describe your experience with our product?", type: "radiogroup", choices: [ { value: 5, text: "Fully satisfying" }, { value: 4, text: "Generally satisfying" }, { value: 3, text: "Neutral" }, { value: 2, text: "Rather unsatisfying" }, { value: 1, text: "Not satisfying at all" } ], isRequired: true }, { name: "nps-score", title: "On a scale of zero to ten, how likely are you to recommend our product to a friend or colleague?", type: "rating", rateMin: 0, rateMax: 10, }], completedHtml: "Thank you for your feedback!", }; const surveyResults = [ { "satisfaction-score": 5, "nps-score": 10 }, { "satisfaction-score": 5, "nps-score": 9 }, { "satisfaction-score": 3, "nps-score": 6 }, { "satisfaction-score": 3, "nps-score": 6 }, { "satisfaction-score": 2, "nps-score": 3 } ]; export default function DashboardComponent() { const [dashboard, setDashboard] = useState(null); useEffect(() => { const survey = new Model(surveyJson); const dashboardInstance = new Dashboard({ questions: survey.getAllQuestions(), data: surveyResults, items: [ "satisfaction-score", { name: "nps-score", type: "nps" } ] }); setDashboard(dashboardInstance); dashboardInstance.render("dashboard"); return () => { dashboardInstance.clear(); }; }, []); return (
); } ``` ```js // dashboard/page.tsx import dynamic from "next/dynamic"; const Dashboard = dynamic(() => import('@/components/Dashboard'), { ssr: false, }); export default function SurveyDashboard() { return ( ); } ``` -------------------------------- ### Configure Dashboard with items array in Angular Source: https://github.com/surveyjs/survey-analytics/blob/master/docs/get-started-angular.md Pass an IDashboardOptions object to the Dashboard constructor to configure the dashboard. Specify the data array to provide survey results. Use the items array to control which items appear and override their configuration. The example sets the default NPS visualization type for the nps-score question. ```JavaScript import { AfterViewInit, Component } from '@angular/core'; import { Model } from 'survey-core'; import { Dashboard } from 'survey-analytics'; const surveyJson = { /* ... */ }; const surveyResults = [ /* ... */ ]; @Component({ // ... }) export class AppComponent implements AfterViewInit { ngAfterViewInit(): void { const survey = new Model(surveyJson); const dashboard = new Dashboard({ questions: survey.getAllQuestions(), data: surveyResults, items: [ "satisfaction-score", { name: "nps-score", type: "nps" } ] }); } } ``` -------------------------------- ### Load Survey Results from Backend (Vue 3 script setup) Source: https://github.com/surveyjs/survey-analytics/blob/master/docs/get-started-vue.md Fetches survey results from a backend endpoint using the fetch API. The function loadSurveyResults returns a Promise that resolves to an array of JSON objects. It throws an error if the request fails or the response is not OK. Use this in the onMounted hook to load data for the Dashboard. ```html ``` -------------------------------- ### Pass SurveyModel to Dashboard to inherit survey language Source: https://github.com/surveyjs/survey-analytics/blob/master/docs/localization.md Creates a Dashboard instance using the survey's SurveyModel, so Dashboard controls and chart text use the survey's current language. The schema sets 'locale' to 'fr', so the dashboard starts in French and shows a language selector because default English text is also present. ```js import { Model } from "survey-core"; import { Dashboard } from "survey-analytics"; const survey = new Model(surveyJson); const dashboard = new Dashboard({ questions: survey.getAllQuestions(), data: surveyResults, survey: survey }); dashboard.render("dashboardContainer"); ``` -------------------------------- ### Full Code: HTML and JavaScript for Dashboard Source: https://github.com/surveyjs/survey-analytics/blob/master/docs/get-started-html-css-javascript.md Complete example with HTML page setup and JavaScript configuration. The HTML includes required CDN links for SurveyJS, Chart.js, and Survey Analytics. The JavaScript defines survey questions, results, and dashboard configuration with items array. ```html SurveyJS Dashboard ``` ```js const surveyJson = { elements: [{ name: "satisfaction-score", title: "How would you describe your experience with our product?", type: "radiogroup", choices: [ { value: 5, text: "Fully satisfying" }, { value: 4, text: "Generally satisfying" }, { value: 3, text: "Neutral" }, { value: 2, text: "Rather unsatisfying" }, { value: 1, text: "Not satisfying at all" } ], isRequired: true }, { name: "nps-score", title: "On a scale of zero to ten, how likely are you to recommend our product to a friend or colleague?", type: "rating", rateMin: 0, rateMax: 10, }], completedHtml: "Thank you for your feedback!", }; const survey = new Survey.Model(surveyJson); const surveyResults = [ { "satisfaction-score": 5, "nps-score": 10 }, { "satisfaction-score": 5, "nps-score": 9 }, { "satisfaction-score": 3, "nps-score": 6 }, { "satisfaction-score": 3, "nps-score": 6 }, { "satisfaction-score": 2, "nps-score": 3 } ]; const dashboard = new SurveyAnalytics.Dashboard({ questions: survey.getAllQuestions(), data: surveyResults, items: [ "satisfaction-score", { name: "nps-score", type: "nps" } ] }); ``` -------------------------------- ### Import Tabulator and instantiate with survey model and results Source: https://github.com/surveyjs/survey-analytics/blob/master/docs/set-up-table-view-vue.md Import the Tabulator component from 'survey-analytics/survey.analytics.tabulator' and create an instance by passing the survey model and generated data. The instance is assigned to a constant for later rendering. ```html ``` -------------------------------- ### Build Commands (npm run build, build:all, build:dev, build:prod, watch:dev) Source: https://github.com/surveyjs/survey-analytics/blob/master/CLAUDE.md Full build pipeline: build:dev + build:prod (UMD) + rollup -c (esm) + build:types. build:all is an alias for build. build:dev emits non-source files and styles; build:prod produces the UMD prod bundle; watch:dev runs rollup -w for development. ```bash npm run build # full build: build:dev + build:prod (UMD) + rollup -c (esm) + build:types ``` ```bash npm run build:all # alias for build ``` ```bash npm run build:dev # UMD dev bundle, emits non-source files + styles ``` ```bash npm run build:prod # UMD prod bundle ``` ```bash npm run watch:dev # rollup -w for development ``` -------------------------------- ### Build the library with npm run build Source: https://github.com/surveyjs/survey-analytics/blob/master/README.md Builds the library and outputs scripts and style sheets to the build folder. Use npm run watch:dev for development. ```sh npm run build ``` -------------------------------- ### Import Tabulator and create survey data table Source: https://github.com/surveyjs/survey-analytics/blob/master/docs/set-up-table-view-react.md Import the Tabulator component from 'survey-analytics/survey.analytics.tabulator' and create a new Tabulator instance with the survey model and results. Save the instance in a state variable for later rendering. ```js // components/Tabulator.tsx // ... import { useState } from 'react'; import { Model } from 'survey-core'; import { Tabulator } from 'survey-analytics/survey.analytics.tabulator'; const surveyJson = { /* ... */ } interface INpsDataObject { /* ... */ } function generateData(): Array { /* ... */ } export default function TableViewComponent() { const [survey, setSurvey] = useState(); const [surveyDataTable, setSurveyDataTable] = useState(); const [surveyResults, setSurveyResults] = useState>(generateData()); if (!survey) { const survey = new Model(surveyJson); setSurvey(survey); } if (!surveyResults) { setSurveyResults(generateData()); } if (!surveyDataTable && !!survey) { const surveyDataTable = new Tabulator( survey, surveyResults ); setSurveyDataTable(surveyDataTable); } return "..."; } ```