JavaScript - auto sort and bar graph | XM Community
Skip to main content

Hi, I am trying to take the survey results, aggregate the information, then share it back to the person taking the survey. I was able to create the following code which does just that. However, rather than have a button that the user has to push in order to sort the table, I want the table to auto sort, and only present the top 3 choices. I would also like to take this information and present it as a bar graph. I have tried using the onload function, but it does not work for me. So far, my code works to create a table that the user clicks a button to sort. Here is the code and an image of table.
Screenshot 2023-01-09 152841.pngAny help with getting this to auto sort and display a bar graph would be greatly appreciated.




Sort Attributes Most Important to Least Important







Click the button to sort the table numerically:





 
  
  
 
 
  
  
 
 
  
  
 
 
  
  
 
 
  
  
 
 
  
  
 
 
  
  
 
 
  
  
 
 
IDAttribute
$e{ q://QID2/SelectedAnswerRecode/3 + q://QID4/SelectedAnswerRecode/2 + q://QID12/SelectedAnswerRecode/4 + q://QID11/SelectedAnswerRecode/1 }Living Longer
$e{ q://QID1/SelectedAnswerRecode/1 + q://QID4/SelectedAnswerRecode/3 + q://QID10/SelectedAnswerRecode/4 + q://QID11/SelectedAnswerRecode/2 }Maintain day-to-day activity
$e{ q://QID9/SelectedAnswerRecode/4 + q://QID12/SelectedAnswerRecode/2 + q://QID11/SelectedAnswerRecode/3 }Avoid short-term side effects
$e{ q://QID1/SelectedAnswerRecode/4 + q://QID4/SelectedAnswerRecode/1 + q://QID9/SelectedAnswerRecode/2 + q://QID12/SelectedAnswerRecode/3 }Avoid long-term side effects
$e{ q://QID1/SelectedAnswerRecode/3 + q://QID2/SelectedAnswerRecode/2 + q://QID9/SelectedAnswerRecode/1 + q://QID11/SelectedAnswerRecode/4 }Avoid high financial costs
$e{ q://QID1/SelectedAnswerRecode/2 + q://QID2/SelectedAnswerRecode/4 + q://QID10/SelectedAnswerRecode/3 + q://QID12/SelectedAnswerRecode/1 } Avoid becoming more dependent on others
$e{ q://QID2/SelectedAnswerRecode/1 + q://QID4/SelectedAnswerRecode/4 + q://QID9/SelectedAnswerRecode/3 + q://QID10/SelectedAnswerRecode/2 }Avoid hospitalizations






Cant we use Show Response Summary to show the show the respondents a survey overview with their answers selected? This gives respondents the option to download the individual response as a PDF.


Thank you for this response Vinoth_Mathaiyan. I have looked into that as well, but that only will display actual responses. The report that I am sharing back to the respondent have been calculated based on their responses.


To sort the table automatically when the page loads, you can move the function call to the onload event in the body element. You can add the following line of code to your HTML file:

Regarding the chart, we need to check if it is possible to import the JS library to show the Charts in Qualtrics. Let me know if it helps!


Vinoth_Mathaiyan Thank you. I had tried this previously, but was continuing to find errors. I just realized that I had to remove the

Scanning file for viruses.

Sorry, we're still checking this file's contents to make sure it's safe to download. Please try again in a few minutes.

OK

This file cannot be downloaded

Sorry, our virus scanner detected that this file isn't safe to download.

OK