/
FormOxyPlot.cs
164 lines (132 loc) · 5.98 KB
/
FormOxyPlot.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
using System;
using System.Windows.Forms;
using OxyPlot;
using OxyPlot.Extensions;
using OxyPlot.Series;
using OxyPlot.Axes;
using OxyPlotApp.DomainModel.Model;
using OxyPlotApp.DomainModel.Interfaces.Service;
namespace OxyPlotApp.Winforms
{
public partial class FormOxyPlot : Form
{
private readonly ICategoriaService _categoriaService;
private readonly IVariavelService _variavelService;
public FormOxyPlot(ICategoriaService categoriaService, IVariavelService variavelService)
{
_categoriaService = categoriaService;
_variavelService = variavelService;
InitializeComponent();
cbLegenda.CheckedChanged += cbLegenda_CheckedChanged;
btnLines.Click += btnLines_Click;
btnFunctionSeries.Click += btnFunctionSeries_Click;
btnLimpar.Click += btnLimpar_Click;
}
private void cbLegenda_CheckedChanged(object sender, System.EventArgs e)
{
plotView1.Model.IsLegendVisible = ((CheckBox)sender).Checked;
plotView1.Update();
}
private void btnLimpar_Click(object sender, System.EventArgs e)
{
plotView1.Model = null;
}
private void configurarPlotModel(PlotModel plotModel)
{
plotModel.Background = OxyColors.White;
}
private void btnLines_Click(object sender, System.EventArgs e)
{
plotView1.Focus();
var xseries = new double[] { 1, 2, 3 };
var yseries1 = new double[] { 1, 2, 3 };
var yseries2 = new double[] { 0.5, 1, 1.5 };
var zseries3 = new double[] { 1, 2, 3, 4, 5 };
var plotModel = new PlotModel { Title = "LinesSeries with ScatterSeries" };
plotModel.AddScatterSeries(xseries, yseries1, OxyColors.Red);
plotModel.AddHighlightedPoint(2.5, 2.5, OxyColors.Blue);
plotModel.AddLineSeries(xseries, yseries2);
plotModel.AddLineSeries(xseries, zseries3);
plotView1.Model = plotModel;
configurarPlotModel(plotModel);
}
private void btnFunctionSeries_Click(object sender, System.EventArgs e)
{
plotView1.Focus();
var xseries = new double[] { 1, 2, 3 };
var yseries1 = new double[] { 1, 2, 3 };
var yseries2 = new double[] { 0.5, 1, 1.5 };
var zseries3 = new double[] { 1, 2, 3, 4, 5 };
var plotModel = new PlotModel { Title = "BarSeries" };
plotModel.AddScatterSeries(xseries, yseries1, OxyColors.Red);
plotModel.AddHighlightedPoint(2.5, 2.5, OxyColors.Blue);
plotModel.AddLineSeries(xseries, yseries2);
plotModel.AddLineSeries(xseries, zseries3);
plotModel.Series.Add(new FunctionSeries(Math.Cos, 0, 10, 0.1, "cos(x)"));
plotView1.Model = plotModel;
configurarPlotModel(plotModel);
}
private void btnPointSeries_Click(object sender, EventArgs e)
{
plotView1.Focus();
var dateAxis = new DateTimeAxis(AxisPosition.Bottom, "Date", "dd/MM/yyyy") { MajorGridlineStyle = LineStyle.Solid, MinorGridlineStyle = LineStyle.Dot, IntervalLength = 80 };
var valueAxis = new LinearAxis(AxisPosition.Left, 0) { MajorGridlineStyle = LineStyle.Solid, MinorGridlineStyle = LineStyle.Dot, Title = "Value" };
var plotModel = new PlotModel { Title = "BarSeries" };
plotModel.LegendTitle = "Legend";
plotModel.LegendOrientation = LegendOrientation.Horizontal;
plotModel.LegendPlacement = LegendPlacement.Outside;
plotModel.LegendPosition = LegendPosition.TopRight;
plotModel.LegendBackground = OxyColor.FromAColor(200, OxyColors.White);
plotModel.LegendBorder = OxyColors.Black;
plotModel.Axes.Add(dateAxis);
plotModel.Axes.Add(valueAxis);
plotView1.Model = plotModel;
configurarPlotModel(plotModel);
}
private void btnColumnSeries_Click(object sender, EventArgs e)
{
plotView1.Focus();
var categorias = _categoriaService.GetCategorias();
foreach (var categoria in categorias)
{
categoria.Variaveis = _variavelService.GetVariaveis();
}
var categoriaAxis = new CategoryAxis();
categoriaAxis.ItemsSource = categorias;
categoriaAxis.LabelField = "Nome";
var linearAxis = new LinearAxis();
linearAxis.Position = AxisPosition.Left;
linearAxis.MinimumPadding = 0;
linearAxis.AbsoluteMinimum = 0;
var plotModel = new PlotModel { Title = "ColumnSeries" };
plotModel.Axes.Add(categoriaAxis);
plotModel.Axes.Add(linearAxis);
foreach (var categoria in categorias)
{
foreach (var variavel in categoria.Variaveis)
{
var columnSeries = new ColumnSeries();
columnSeries.Title = variavel.Data.ToString("dd/MM/yyyy");
columnSeries.ItemsSource = categoria.Variaveis;
columnSeries.ValueField = "Valor";
plotModel.Series.Add(columnSeries);
}
}
plotView1.Model = plotModel;
configurarPlotModel(plotModel);
}
private void btnLineSeries_Click(object sender, EventArgs e)
{
plotView1.Focus();
var lineSeries = new LineSeries();
lineSeries.Points.Add(new DataPoint(0, 0));
lineSeries.Points.Add(new DataPoint(10, 4));
lineSeries.Points.Add(new DataPoint(30, 2));
lineSeries.Points.Add(new DataPoint(40, 12));
var plotModel = new PlotModel { Title = "LineSeries" };
plotModel.Series.Add(lineSeries);
plotView1.Model = plotModel;
configurarPlotModel(plotModel);
}
}
}