15,882,152 members
See more:
Hello Friends, I am Brazilian, sorry if my english has some error. I have a very basic question. 'm Inciante in C #, I would like to know a simple way to plot a graph of sine where through a numeric up down box, I can vary the frequency of the graph. I'm using a panel for this task. Thank you! My email to contact is [Edited away].

Att

Christiano De Carli
Caxias do Sul - Brazil
Posted
Updated 5-Jun-14 1:27am
v2
S Houghtelin 5-Jun-14 7:23am
You would do well to remove your email from your post, unless you want a lot of spam. When someone answers your question you will automatically get an email.
ZurdoDev 5-Jun-14 7:24am
Use the chart control.

## Solution 2

You can use your up down box to set the variables in this simple function to generate a sine wave of the desired frequency and sample rate.
C#
```class SineGen
{
public double phaseCnt = 0;     // Sample location in sine wave
public double sampleRate = 300; // Number samples in one second
public double freq = 10000;     // Desired frequency, Default set to 10Khz

/* Simple Sine Wave Generator
* Make a call to this function for every point
* in the wave form.
*/
public double sineWave()
{
double result = Math.Sin(freq * (2 * Math.PI) * (phaseCnt) / sampleRate);
phaseCnt++;
if (phaseCnt > sampleRate) phaseCnt = 0;
return result;
}
}```

Within the loop or timer event you can populate a chart control using following lines of code.
C#
```mySineWave = _SineGen.sineWave();
```

For more on chart controls see here: ASP.NET 4.0 Chart Control[^]

Good luck.

## Solution 1

Christiano De Carli 5-Jun-14 7:39am
What is Zed Graph? How active this function in Visual Studio?

Top Experts
Last 24hrsThis month
 Graeme_Grant 40 Rick York 10 Maciej Los 10 OriginalGriff 10 Member 16247227 -22
 Pete O'Hanlon 1,940 OriginalGriff 1,415 Graeme_Grant 935 Richard Deeming 853 Dave Kreskowiak 694

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900