-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExampleChartBuilder.cs
More file actions
42 lines (36 loc) · 1.34 KB
/
ExampleChartBuilder.cs
File metadata and controls
42 lines (36 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System;
using System.Windows.Forms.DataVisualization.Charting;
namespace Computer_Modeling_Task
{
public static class ExampleChartBuilder
{
private const int valuesCount = 15;
private const int minRandomValue = 1;
private const int maxRandomValue = 21;
public static readonly string SeriesName = "XY_ExampleValues";
public static void BuildExampleChart(Chart chart)
{
int[] yValues = GetValues();
DrawChartValues(chart, yValues);
}
private static int[] GetValues()
{
var random = new Random();
var values = new int[valuesCount];
for (int i = 0; i < valuesCount; i++)
values[i] = random.Next(minRandomValue, maxRandomValue);
return values;
}
private static void DrawChartValues(Chart chart, int[] yValues)
{
if (chart.Series.FindByName(SeriesName) == null)
{
chart.Series.Add(new Series(SeriesName));
chart.Series[SeriesName].ChartType = SeriesChartType.Spline;
chart.Series[SeriesName].Color = System.Drawing.Color.Red;
}
for (int i = 0; i < valuesCount; i++)
chart.Series[SeriesName].Points.AddXY(i, yValues[i]);
}
}
}