Hello,
I am inexperienced with Javascript but by viewing other Community posts my team was able to create a horizontal bar graph that displays survey results from the previous block. The issue I am having is with the backgroundColor section. You can see I have 9 different background colors for the 9 variables and they vary in opacity. I need to find a way of displaying these background opacities based on how 9 different questions are answered. If the question is answered with a 1, I need to display the highest opacity, if answered with a 10 I need to display the lowest opacity.
Is this possible to do?
See code below
Qualtrics.SurveyEngine.addOnReady(function()
{
var ctx = document.getElementById("myChart").getContext('2d');
var myChart = new Chart(ctx, {
type: 'horizontalBar',
data: {
labels: ["Aggression","Disruption","Noncompliance","Hyperactivity","Inattention","Impulsivity","Anxiety","Feeling sad","Irritability"],
datasets: [{
label: 'Ratings',
data: ["${q://QID6/ChoiceNumericEntryValue/1}","${q://QID11/ChoiceNumericEntryValue/1}","${q://QID43/ChoiceNumericEntryValue/1}","${q://QID47/ChoiceNumericEntryValue/1}","${q://QID51/ChoiceNumericEntryValue/1}","${q://QID55/ChoiceNumericEntryValue/1}","${q://QID59/ChoiceNumericEntryValue/1}","${q://QID63/ChoiceNumericEntryValue/1}","${q://QID67/ChoiceNumericEntryValue/1}"],
backgroundColor: [
'rgba(0, 0, 255, 0.05)',
'rgba(0, 0, 255, 0.17)',
'rgba(0, 0, 255, 0.29)',
'rgba(0, 0, 255, 0.41)',
'rgba(0, 0, 255, 0.53)',
'rgba(0, 0, 255, 0.65)',
'rgba(0, 0, 255, 0.77)',
'rgba(0, 0, 255, 0.89)',
'rgba(0, 0, 255, 1.0)'
],
borderColor: [
'rgba(0, 0, 255, .05)'
],
borderWidth: 2
}]
},
options: {
scales: {
xAxes: [{
ticks: {
min: 0,
max: 9,
stepSize: 1,
}
}]
}
}
});
});
Best answer by ahmedA
View original