I'm building a survey in react using Survey JS. After users choose a multiple choice option, I'm hoping to display a graph of all previous answers as per https://surveyjs.io/Examples/Library/?id=service-result&platform=Reactjs&theme=default
var surveySendResult = function (s, options) {
if (options.success) {
s.getResult('a15eee7a-9418-4eb4-9671-2009c8ff6b24', 'langs');
}
};
var surveyGetResult = function (s, options) {
if (options.success) {
showChart(options.dataList);
}
};
function showChart(chartDataSource) {
document
.getElementById("chartContainer")
.style
.height = "500px";
$("#chartContainer").dxPieChart({
dataSource: chartDataSource,
series: {
argumentField: 'name',
valueField: 'value'
}
});
}
Survey
.StylesManager
.applyTheme("default");
var json = {
surveyId: '5af48e08-a0a5-44a5-83f4-1c90e8e98de1',
surveyPostId: '3ce10f8b-2d8a-4ca2-a110-2994b9e697a1'
};
window.survey = new Survey.Model(json);
survey
.onComplete
.add(function (result) {
document
.querySelector('#surveyResult')
.textContent = "Result JSON:\n" + JSON.stringify(result.data, null, 3);
});
ReactDOM.render(<Survey.Survey model={survey} onSendResult={surveySendResult} onGetResult={surveyGetResult}/>, document.getElementById("surveyElement"));
When you implement this in a create-react-app build though, you get console errors and the results do not display. The errors say "Warning: setState(...): Cannot update during an existing state transition", and that chartContainer is not a function.
Any help would be greatly appreciated.