Until stimulated by this question to investigate, I didn’t know that Visual Studio/C# has a built in graphing facility. Here is an example for anyone who digs up this question in the future.
You need a pointer to the right library depending on whether you are using a Web Form or a Windows Form.
In my example, I set up an alias for simplicity:
using Charting = System.Windows.Forms.DataVisualization.Charting;
You need a Chart object. You can drag one from the tool box. See link to msdn.Microsoft in the program text. In the example, it’s named MyChart.
Poly() is a function that returns values for the polynomial with roots at the integers 1,2,…9. Everything else is straightforward. There may need to be some changes for Web Forms.
private void btnChart_Click(object sender, EventArgs e)
// Helpful links
MyChart.Visible = true;
MyChart.Palette = Charting.ChartColorPalette.Bright;
Charting.Title chtTitle = new System.Windows.Forms.DataVisualization.Charting.Title();
System.Drawing.Font chtFont = new System.Drawing.Font("Arial", 16);
chtTitle.Font = chtFont;
chtTitle.Text = "Polynomial Chart Example";
// Create Series
MyChart.Series["Polynomial"].ChartType = Charting.SeriesChartType.Line; ;
// populate Series
for (int i=9; i <= 91; i++)
double x = 0.1 * Convert.ToDouble(i);
double Poly(double x)
double y = 1.0;
for (double c = 1.0; c < 10.0; c += 1.0) y = y * (x - c);
The Print and SaveImage methods worked fine for me.There are issues and complications having to do with scale. There is some discussion at the link to Stack Overflow.
There are also issues with the labeling of the X-axis. In the example, grid lines are at 0.8, 2.8, 4.8, 6.8, 8.8. It would be nice to have them at integers. I have not tried control this X-axis format, but it may have to be done on a graph-by-graph basis.
You can find lots of examples on the internet once you know what to look for.