II
See results in a dashboard
You need this: When people need to see answers, not just store them.
SurveyJS Dashboard runs in the browser. Your backend returns the stored responses; the client hands them to the Dashboard together with the definition, and it picks a chart per question type. One endpoint returns the responses for a form. For large volumes, filter by date or paginate on the server instead of sending everything to the browser.
This step on the Server Integration page
Source on GitHub
Commercial client licence: without SURVEYJS_LICENSE_KEY the component shows a licence banner
Try this
Code that just ran
These regions are read from the files that served this page, the same lines the Server Integration page shows.
shared/client/dashboard.js · sjs:II.client
View on GitHub
import { Model } from "survey-core";
import { VisualizationPanel } from "survey-analytics";
async function showDashboard(from) {
const { definition } = await fetch("/api/forms/feedback").then(r => r.json()); // .definition: the I.2 endpoint
const responses = await fetch(`/api/responses?formId=feedback&from=${from}`).then(r => r.json());
const survey = new Model(definition);
const dashboard = new VisualizationPanel(survey.getAllQuestions(), responses);
dashboard.render(document.getElementById("dashboard"));
return dashboard;
}
routes/examples/dashboard.php · sjs:II.server
View on GitHub
// GET /api/responses?formId=&from=&limit=&offset= — the stored answers as an array
Route::get('/api/responses', function (Request $request) {
$documents = DB::table('responses')
->where('form_id', $request->query('formId'))
->where('created_at', '>=', $request->query('from', '1970-01-01')) // ISO-8601 UTC strings compare as dates
->orderBy('created_at')
->limit(min(max((int) $request->query('limit', 500), 1), 5000)) // filter or page on the server for large volumes
->offset(max((int) $request->query('offset', 0), 0))
->pluck('data');
return response('['.$documents->implode(',').']') // documents as stored, not re-encoded
->header('Content-Type', 'application/json');
});
Definition: shared/definitions/dashboard.json