0

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.

  • Right now we're working on this issue - https://github.com/surveyjs/survey-library/issues/1846 and deprecated warnings will be fixed soon. But as you can see in this example - https://surveyjs.io/Examples/Library/?id=service-result&platform=Reactjs&theme=default - these warnings don't affect survey operation and chart results representation – TSV Sep 27 '19 at 13:55
  • Thank you for the response and help. The react app won't compile because 'survey' is not defined after 'window.survey = new Survey.Model(json);'. – Ashley Brandon Sep 29 '19 at 20:12
  • Probably scripts are not loaded. Please check our https://github.com/surveyjs/surveyjs_react_quickstart repo. Or if you share a minimal sample I can take a look – TSV Sep 30 '19 at 10:54

0 Answers0