I have made a survey in Qualtrics, and I want to present a chart to respondents based on their answers. I have stored four weights in Embedded data. Yet, how do I call or access these embedded data in javascript? In the code below I want to replace the values 10, 20, 30, 40 with weights that are stored in embedded data.

I have found this on the internet, but I am not sure what to do with it.

How to access and write values to an embedded data field at any point in the survey To access embedded data at any time using javascript: simply set a variable to be equal to the piped text required to access to embedded data in survey questions (as a string). For example, var myData = "${e://Field/myEmbeddedData}" (don't forget the quotes!)

But do I have to put this piece of code in the code below or somewhere else? I have tried to do this, and then replace e.g. 10 with {MyData}, but it did not work. Did I do something wrong?

Thank you in advance!

google.charts.load("current", {packages:['corechart']});
function drawChart() {
  var data = google.visualization.arrayToDataTable([
    ['Characteristic', 'Weight', { role: 'style' } ],
    ['one', 10, 'color: #394165'],
    ['two', 20, 'color: #0CA5AA'],
    ['three', 30, 'color: #F2941A'],
    ['four', 40, 'color: #E64E67']

  var view = new google.visualization.DataView(data);
  view.setColumns([0, 1,
                   { calc: function(dt, rowIndex) { return dt.getValue(rowIndex, 1).toString() + '%' },
                     sourceColumn: 1,
                     type: "string",
                     role: "annotation" },

  var options = {
    width: 800,
    height: 600,
    title: 'Chart',
    vAxis:  { format: '#\'%\'', maxValue: '100', minValue: '0'},
    legend: { position: 'none'},
    bar: { groupWidth: '75%' },

  var chart = new google.visualization.ColumnChart(document.getElementById("columnchart_values"));
  chart.draw(view, options);


1 Answers 11

up vote 1 down vote accepted

Like this:

function drawChart() {
  var data = google.visualization.arrayToDataTable([
    ['Characteristic', 'Weight', { role: 'style' } ],
    ['one', parseInt("${e://Field/ed1}"), 'color: #394165'],
    ['two', parseInt("${e://Field/ed2}"), 'color: #0CA5AA'],
    ['three', parseInt("${e://Field/ed3}"), 'color: #F2941A'],
    ['four', parseInt("${e://Field/ed4}"), 'color: #E64E67']

Where ed1, ed2, ed3, and ed4 are your embedded data fields.

Not the answer you're looking for? Browse other questions tagged or ask your own question.