Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Core;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Windows.Forms.DataVisualization.Charting;
- using TrendingGUI.CoreReference;
- namespace TrendingGUI
- {
- public partial class Form1 : Form
- {
- private CoreReference.ITrending proxy;
- public static Dictionary<string, double[]> chartSeries;
- public Form1(CoreReference.ITrending proxy)
- {
- chartSeries = new Dictionary<string, double[]>();
- InitializeComponent();
- this.proxy = proxy;
- trendingChart.ChartAreas[0].AxisX.Title = "Seconds";
- trendingChart.ChartAreas[0].AxisX.TitleFont = new Font(new FontFamily("Arial"), 12);
- trendingChart.ChartAreas[0].AxisY.Title = "Value";
- trendingChart.ChartAreas[0].AxisY.TitleFont = new Font(new FontFamily("Arial"), 12);
- var tags = proxy.getTagsForDisplay();
- foreach (Tag t in tags.Keys)
- {
- comboBox1.Items.Add(t.Name);
- }
- StartDoing();
- }
- private void History(Value[] values, string name)
- {
- int i = 0;
- historyChart.Series[0].Points.Clear();
- historyChart.Series[0].Name = name;
- historyChart.ChartAreas[0].AxisX.Title = "Seconds";
- historyChart.ChartAreas[0].AxisX.TitleFont = new Font(new FontFamily("Arial"), 12);
- historyChart.ChartAreas[0].AxisY.Title = "Value";
- historyChart.ChartAreas[0].AxisY.TitleFont = new Font(new FontFamily("Arial"), 12);
- historyChart.ChartAreas[0].AxisX.Interval = 1;
- historyChart.Series[0].Enabled = true;
- foreach (var value in values.Reverse())
- {
- historyChart.Series[0].Points.AddXY(i++, value.value1);
- }
- }
- public void Update(Dictionary<Tag, double> tagValues)
- {
- List<string> strings = new List<string>();
- int pos = comboBox1.Text.Length;
- comboBox1.Items.Clear();
- comboBox1.Select(pos, 0);
- foreach (Tag t in tagValues.Keys)
- {
- comboBox1.Items.Add(t.Name);
- int index = getCBIndex(t.Name);
- if (index != -1)
- {
- if (!checkedListBox1.GetItemChecked(index))
- trendingChart.Series[t.Name].Enabled = false;
- else trendingChart.Series[t.Name].Enabled = true;
- }
- if (chartSeries.ContainsKey(t.Name))
- {
- chartSeries[t.Name][chartSeries[t.Name].Length - 1] = tagValues[t];
- Array.Copy(chartSeries[t.Name], 1, chartSeries[t.Name], 0, chartSeries[t.Name].Length - 1);
- }
- else
- {
- trendingChart.Series.Add(t.Name);
- trendingChart.Series[t.Name].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline;
- double[] myArray = new double[15];
- for (int i = 0; i < 15; i++) myArray[i] = tagValues[t];
- chartSeries.Add(t.Name, myArray);
- checkedListBox1.Items.Add(t.Name, true);
- }
- strings.Add(t.Name);
- }
- UpdateSeries(strings);
- UpdateChart();
- }
- private int getCBIndex(string t)
- {
- int index = 0;
- foreach (string p in checkedListBox1.Items)
- {
- if (p == t) return index;
- else index++;
- }
- return -1;
- }
- private void UpdateSeries(List<string> strings)
- {
- foreach (string s in chartSeries.Keys.ToList())
- {
- if (!(strings.Contains(s)))
- {
- trendingChart.Series[s].Points.Clear();
- trendingChart.Series.Remove(trendingChart.Series[s]);
- checkedListBox1.Items.Remove(s);
- chartSeries.Remove(s);
- }
- }
- }
- private void UpdateChart()
- {
- int i;
- foreach (string s in chartSeries.Keys)
- {
- trendingChart.Series[s].Points.Clear();
- for (i = 0; i < chartSeries[s].Length - 1; i++)
- {
- trendingChart.Series[s].Points.AddXY(i, chartSeries[s][i]);
- }
- }
- }
- private void button1_Click(object sender, EventArgs e)
- {
- History(proxy.getValuesFromDatabaseGUI(comboBox1.Text), comboBox1.Text);
- }
- private void StartDoing()
- {
- timer1.Start();
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
- Update(proxy.getTagsForDisplay());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement