Hiding a Category of a Question
Removes a category from a question but does not rebase it. This is automating the process of right-clicking on a category and selecting Hide.
var age = project.dataFiles[0].getQuestionByName('Age');
age.dataReduction.hide("Don't know");
The first line of this code finds a question named Age in the first data file (note that [0] finds the first data file, [1] would find the second, etc. ) and assigns it to a variable called age.
The second line of the code modifies the question called age. It does so using the question’s DataReduction. The DataReduction is the object that stores which categories have been merged together, which have been hidden, what their names are and what order they are shown in. Thus, the hide instruction is hiding the Don’t know category and this will cause the category not to appear when this question is used to create tables and charts.
See also
- Next worked example.
- QScript for an explanation of how to run this code.
- QScript Examples Library for other examples.
- QScript Reference for technical information.
- JavaScript for information about the JavaScript programming language.
- Table JavaScript and Plot JavaScript for tools for using JavaScript to modify the appearance of tables and charts.
- JavaScript Variables for detail on how to create new variables in the Variables and Questions tab using JavaScript.