Your requirements can be broken down into two parts:
1. How to determine the value history of a particular story variable.
The following JavaScript code, which needs to be place within your project's Story Javascript area, defines a valueHistory() function on the setup object which uses the State API to determine both the current and previous values of a story varaible..
/*
setup.valueHistory(variableName)
Arguments:
variableName: The name (without $) of the Story Variable to want the history for.
Returns:
An Array containing each of the values (in moment order) that the variable was assigned.
Example:
/% Assuming assignment of a variable like <<set $counter to 10>> %/
Counter History: <<= setup.valueHistory('counter')>>
*/
setup.valueHistory = function (variableName) {
var values = [];
var previous = null;
/* Check the past. */
if (State.length) {
for (var i = 0; i < State.length; i++) {
var V = State.index(i).variables;
if (V.hasOwnProperty(variableName) && V[variableName] != previous) {
previous = V[variableName];
values.push(previous);
}
}
}
/* Check the present. */
V = State.variables;
if (V.hasOwnProperty(variableName) && V[variableName] != previous) {
values.push(V[variableName]);
}
return values;
};
2. How to graph the value history of the story variable.
@HiEv indicated a Javascript library that you may be able to use to do this, if you have issues using it then you may want to add to this question later, or even create a new question.