Using sliders to change a bar chart

May 25, 2015

I wonder how to set this up correctly:

I have two variables A and B. I change their values with two sliders S1=A and S2=B. I want to add these two numbers in the Sum variable by using the +Add trigger.

I would like Sum to change the states of a bar chart. If the Sum value is high the bar is high. If the Sum values is lowered the Sum bar should decrease.

This works fine first time I drag the slider. But each time I change the slider position a new value is adds to A or B and then of course into Sum. Obviously +Add is not the best choice here.

Is there a way to combine two variables into one new variable and then adjust a bar chart according to the later?



9 Replies
Tim Shelton

I have given this some thought. You can find articles which will explain adding two variables together into a 3rd, however most of these use a button to clear and calculate the sum. Trying to do this on the slider is a problem due to the lack of triggers you can assign to the slider control i.e. on slider moves.

You can do it in Javascript without too much difficulty using something like the code below as long as you can action it each time a slider is used. [This is very rough JS it may be wrong but it is close to what you need, I dont use JS everyday]

var player = GetPlayer();

var Z =null;

var X =player.GetVar("sliderX");

var Y =player.GetVar("sliderY");

var Z = X + Y;

player.SetVar("total", Z);

Then in terms of having it affect the graph, make sure you create an object with enough states to cater for all potential answers e.g. slider 1 = 0-10 & slider 2 = 0-10 THEN Answers range from 0-40 therefore the object would need 40 states. 

Then all those states need triggers:  change state of object to state38 if Total=38

I hope this helps. If someone can clarify my JS that would be good, and if someone comes up with a solution I defer to their better logic.

Tim out.


Tim Shelton

Ah there is an issue with JS working locally unless you go through the annoying steps to get it set up in Chrome... best to host the course somewhere so it can be viewed as a true webpage.

Also to answer you Q, everytime a slider is dragged or everytime that 'variable changes' might be better. Actually that might be a better way to calculate it using 'variable changes'. hmmm i will have a think on this, but have a try anyway.

This discussion is closed. You can start a new discussion or contact Articulate Support.