-
Notifications
You must be signed in to change notification settings - Fork 1
/
Charter.cs
63 lines (50 loc) · 1.9 KB
/
Charter.cs
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms.DataVisualization.Charting;
using System.IO;
using System.Drawing;
namespace Loan_Projection
{
class Charter
{
public static void MakeChart(string filename, string[] months, double[] cashValues, double[] debtValues)
{
Chart ch = new Chart();
ch.Width = 2000;
ch.Height = 1000;
ChartArea area = new ChartArea();
area.AxisX.Interval = 2;
area.AxisX.Title = "Month";
area.AxisX.LineColor = Color.LightGray;
area.AxisX.MajorGrid.LineColor = Color.LightGray;
area.AxisY.Interval = 2; // 2 billion
area.AxisY.Title = "Amount - $B";
area.AxisY.LineColor = Color.LightGray;
area.AxisY.MajorGrid.LineColor = Color.LightGray;
ch.ChartAreas.Add(area);
Series cash = new Series();
cash.Color = Color.Green;
cash.ChartType = SeriesChartType.FastLine;
cash.Points.DataBindXY(months, scaleDown(cashValues, 9)); // 9 = 10^9 value scale downard
Series debt = new Series();
debt.Color = Color.Red;
debt.ChartType = SeriesChartType.FastLine;
debt.Points.DataBindXY(months, scaleDown(debtValues, 9));
ch.Series.Add(cash);
ch.Series.Add(debt);
FileStream output = File.Open(filename, FileMode.Create);
ch.SaveImage(output, ChartImageFormat.Png);
output.Close();
}
private static double[] scaleDown(double[] input, int amount)
{
double[] output = new double[input.Length];
for (int i = 0; i < input.Length; i++)
output[i] = input[i] / Math.Pow(10.0, amount);
return output;
}
}
}