# Action Button reveals graph?

How can I have the action button reveal the graph of a function that already exists in the calculator?

1 Like

Absolutely!
Try something like thisâ€¦

In calculator (note that â€śhowGraphâ€ť should be in subscript)

``````f(x)=9x+1 {showGraph=1}
``````

In the Graphâ€™s CL

``````this.number("s_{howGraph}"): when myActionButton.pressCount>0 1 otherwise 0
``````

The CL will set the showGraph variable to 1 or 0 depending on whether or not the button has been pressed at least once. The curly braces on the calculator are a restriction so that the function is only graphed when showGraph equals 1.

If that isnâ€™t clear or doesnâ€™t immediately work for you, let me know and I can make you an example to send you.

Thanks for the rapid response. Unfortunately I couldnâ€™t get this to work. When I enter the command

``````this.number("s_{howGraph}"): when myActionButton.pressCount>0 1 otherwise
``````

in the Graph CL I get an error â€śunterminated stringâ€ť What is the this object, I donâ€™t see it in the documentation. And why is the subscript notation used?

Bruce Samuels

Take a look at thisâ€¦

Again, let me know if that still doesnâ€™t help.

Thanks so much, that works fine.

Is there a way to do this with having just a point to show up , instead of a whole function?

Yes, just put the condition inside the parentheses of the point.

Example:
A=(0,2 {s_howgraph=1})

It does affect the moveability though because the 2 gets â€ślockedâ€ť, unless itâ€™s determined by a function, although technically still not freely moveable.

A=(0,f(0) {s_howgraph=1})

1 Like

Is there a way to make a button show and hide a graph? (click to show, click to hide, click to show, click to hide) for at least a few iterations?

`showGraph = numericValue("\mod(\${yourButtonName.pressCount},2)")`

This would cycle the variable between 0 and 1. If you want to hide an entire graph component, you could use:
`hidden: showGraph = 0`

Or if there are individual functions or points in a graph (as in my post above yours), you can set a variable in the graph to the variable above:
`number("s_{howgraph}"): showGraph`

You can do something similar to change the button label.

Thank you!! I am super new to this and do not understand coding at all. Can you tell me what all would I enter into the graphâ€™s CL script?

Currently I have this entered, which makes the graph show up when the button is pressed:
number(â€śs_{howGraph}â€ť): when button1.pressCount>0 1 otherwise 0

This:

``````showGraph = numericValue("\mod(\${button1.pressCount},2)")
number("s_{howGraph}"): showGraph
``````

The first line creates a variable that just exists in the CL. The second line sets a variable in the graph to the first.

THANK YOU!!! Literally so excited right now! Hereâ€™s an example of it!