Added Charts

This commit is contained in:
Jannick van Ballegooijen
2015-10-16 22:05:21 +02:00
parent ae803e7f6c
commit 511766c6e9
4 changed files with 167 additions and 13 deletions
@@ -0,0 +1,102 @@
using ErgometerLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
namespace ErgometerApplication
{
public class ChartPanel:Panel
{
private Chart chart;
private MetingType type;
private ChartArea chartArea;
private Series series;
public ChartPanel(MetingType type) : base()
{
this.type = type;
this.chart = new Chart();
this.chartArea = new ChartArea();
this.chart.Titles.Add(new Title(type.ToString()));
this.Location = new System.Drawing.Point(0, 0);
this.Size = new System.Drawing.Size(250, 200);
this.Controls.Add(chart);
this.series = createSerie();
this.chartArea.Name = "chartArea";
this.chart.Size = new System.Drawing.Size(250, 200);
this.chart.Dock = DockStyle.Fill;
this.chart.Series.Add(series);
this.chart.Text = "chart";
this.chart.ChartAreas.Add(chartArea);
}
public void updateChart(List<Meting> metingen)
{
chart.Series[0] = createSerie();
for (int i = 0; i < metingen.Count; i++)
{
chart.Series[0].Points.Add(getMetingType(metingen[i]));
}
chart.Update();
}
public Series createSerie()
{
Series serie = new Series();
serie.Name = "series";
serie.ChartType = SeriesChartType.Line;
serie.ChartArea = "chartArea";
serie.BorderWidth = 3;
return serie;
}
public int getMetingType(Meting meting)
{
switch(type)
{
case MetingType.HEARTBEAT:
return meting.HeartBeat;
case MetingType.RPM:
return meting.RPM;
case MetingType.SPEED:
return (int)meting.Speed;
case MetingType.DISTANCE:
return (int)meting.Distance;
case MetingType.POWER:
return meting.Power;
case MetingType.ENERGY:
return meting.Energy;
case MetingType.SECONDS:
return meting.Seconds;
case MetingType.ACTUALPOWER:
return meting.ActualPower;
default:
return 0;
}
}
public enum MetingType
{
HEARTBEAT,
RPM,
SPEED,
DISTANCE,
POWER,
ENERGY,
SECONDS,
ACTUALPOWER
}
}
}
@@ -62,8 +62,9 @@ namespace ErgometerApplication
//
// panelClientContainer
//
this.panelClientContainer.Controls.Add(this.panelDataViewLeft);
this.panelClientContainer.Controls.Add(this.panelGraphView);
this.panelClientContainer.Controls.Add(this.panelDataViewLeft);
this.panelClientContainer.Controls.Add(this.panelClientChat);
this.panelClientContainer.Dock = System.Windows.Forms.DockStyle.Fill;
this.panelClientContainer.Location = new System.Drawing.Point(0, 0);
@@ -87,15 +88,6 @@ namespace ErgometerApplication
this.panelDataViewLeft.Controls.Add(energy);
this.panelDataViewLeft.Controls.Add(actualpower);
//
// panelGraphView
//
this.panelGraphView.BackColor = System.Drawing.SystemColors.ButtonFace;
this.panelGraphView.Dock = System.Windows.Forms.DockStyle.Fill;
this.panelGraphView.Location = new System.Drawing.Point(0, 0);
this.panelGraphView.Name = "panelGraphView";
this.panelGraphView.Size = new System.Drawing.Size(400, 600);
this.panelGraphView.TabIndex = 1;
//
// panelClientChat
//
@@ -43,6 +43,8 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Windows.Forms.DataVisualization" />
<Reference Include="System.Windows.Forms.DataVisualization.Design" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
@@ -54,6 +56,9 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ChartPanel.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="ChatItem.cs">
<SubType>Component</SubType>
</Compile>
@@ -1,4 +1,5 @@
using System;
using ErgometerLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -9,17 +10,71 @@ namespace ErgometerApplication
{
public class PanelGraphView:Panel
{
private List<ChartPanel> charts;
private FlowLayoutPanel flowlayout;
public PanelGraphView() : base()
{
createCharts();
flowlayout = new FlowLayoutPanel();
flowlayout.Dock = DockStyle.Fill;
flowlayout.BackColor = System.Drawing.Color.DarkGray;
flowlayout.Location = new System.Drawing.Point(0, 0);
flowlayout.Name = "flowlayout";
flowlayout.Padding = new Padding(15);
flowlayout.AutoScroll = true;
foreach(ChartPanel chart in charts)
{
flowlayout.Controls.Add(chart);
}
List<Meting> metingen = new List<Meting>();
metingen.Add(new Meting(23, 25, 12, 46, 13, 25, 13, 1, 32));
metingen.Add(new Meting(23, 25, 12, 46, 13, 25, 13, 1, 32));
metingen.Add(new Meting(23, 25, 12, 46, 13, 25, 13, 1, 32));
metingen.Add(new Meting(23, 25, 12, 46, 13, 25, 13, 1, 32));
metingen.Add(new Meting(23, 25, 12, 46, 13, 25, 13, 1, 32));
metingen.Add(new Meting(23, 25, 12, 46, 13, 25, 13, 1, 32));
metingen.Add(new Meting(23, 25, 12, 46, 13, 25, 13, 1, 32));
metingen.Add(new Meting(23, 25, 12, 46, 13, 25, 13, 1, 32));
metingen.Add(new Meting(23, 25, 12, 46, 13, 25, 13, 1, 32));
metingen.Add(new Meting(23, 25, 12, 46, 13, 25, 13, 1, 32));
updateAllCharts(metingen);
//
// panelGraphView
//
this.BackColor = System.Drawing.SystemColors.ButtonFace;
this.Dock = System.Windows.Forms.DockStyle.Fill;
this.Location = new System.Drawing.Point(400, 0);
this.Controls.Add(flowlayout);
this.Location = new System.Drawing.Point(0, 0);
this.Name = "panelGraphView";
this.Size = new System.Drawing.Size(400, 600);
this.TabIndex = 1;
}
public void createCharts()
{
charts = new List<ChartPanel>();
charts.Add(new ChartPanel(ChartPanel.MetingType.HEARTBEAT));
charts.Add(new ChartPanel(ChartPanel.MetingType.RPM));
charts.Add(new ChartPanel(ChartPanel.MetingType.SPEED));
charts.Add(new ChartPanel(ChartPanel.MetingType.DISTANCE));
charts.Add(new ChartPanel(ChartPanel.MetingType.ENERGY));
charts.Add(new ChartPanel(ChartPanel.MetingType.SECONDS));
charts.Add(new ChartPanel(ChartPanel.MetingType.POWER));
charts.Add(new ChartPanel(ChartPanel.MetingType.ACTUALPOWER));
}
public void updateAllCharts(List<Meting> metingen)
{
foreach(ChartPanel chart in charts)
{
chart.updateChart(metingen);
}
}
}
}