I have just created a simple windows form to display some data from a MySql table.
What I would like to know is how would I go about displaying this data graphically using some dials and a history graph of data.
This is what I have so far... When you click the button it starts reading and displaying the data in 2 TextBoxes. When you click the button again it stops.
I worked out how to add line graphs, still need to know how to add "dials instead of just TextBoxes...
Worked it out using aGauge...
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 MySql.Data.MySqlClient;
namespace WindowsFormsApplication11
{
public partial class Form1 : Form
{
MySqlConnection mcon = new MySqlConnection("Server=www.inshome.net.au;Port=3306;Database=wordpress;Uid=root;password=********");
MySqlCommand mcd;
MySqlDataReader mdr;
string s;
public Form1()
{
InitializeComponent();
}
private void getTemp_Click(object sender, EventArgs e)
{
// Toggle the timer's enabled state
timer1.Enabled = !timer1.Enabled;
}
private void timer1_Tick(object sender, EventArgs e)
{
try
{
mcon.Open();
s = "SELECT time, dht22temp, dht22humidity FROM shed ORDER BY time DESC LIMIT 1";
mcd = new MySqlCommand(s, mcon);
mdr = mcd.ExecuteReader();
if (mdr.Read())
{
shedTemp.Text = mdr.GetString("dht22temp");
shedHumidity.Text = mdr.GetString("dht22humidity");
aGauge1.Value = float.Parse(mdr.GetString("dht22temp"));
aGauge2.Value = float.Parse(mdr.GetString("dht22humidity"));
this.chart1.Series["Temp"].Points.AddXY(mdr.GetString("time"), mdr.GetString("dht22temp"));
this.chart2.Series["Humidity"].Points.AddXY(mdr.GetString("time"), mdr.GetString("dht22humidity"));
}
else
{
MessageBox.Show("NO DATA");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
mdr.Close();
mcon.Close();
}
}
}
}