public void CreateGraph(ZedGraphControl zg1, SQLiteConnection mbConnection)
{
zg1.GraphPane.CurveList.Clear();
Console.WriteLine("Just Click on Humidity");
GraphData sd = new GraphData();
sd.getGraphData(mbConnection);
// List<Double> valueList = new List<Double>(sd.dateHumidity.Values);
// List<string> keyList = new List<string>(sd.dateHumidity.Keys);
/* for (int i = 0; i < sd.x.Count; i++)
{
pList.Add(sd.x[i], sd.y[i]);
}*/
// get a reference to the GraphPane
GraphPane myPane = zg1.GraphPane;
myPane.Title.FontSpec.Size = 8.0f;
myPane.YAxis.Title.FontSpec.Size = 6.0f;
myPane.XAxis.Title.FontSpec.Size = 6.0f;
myPane.XAxis.Scale.FontSpec.Size = 6.0f;
myPane.YAxis.Scale.FontSpec.Size = 6.0f;
zg1.Refresh();
// Set the title and axis labels
myPane.Title.Text = "Temperature Graph";
myPane.XAxis.Title.Text = "Time(hh:mm:ss)";
myPane.YAxis.Title.Text = "Temperature(°C)";
myPane.XAxis.Scale.FontSpec.Angle = 65;
// Make up some random data points
string[] labels = { "Panther", "Lion", "Cheetah",
"Cougar", "Tiger", "Leopard" };
double[] y4 = { 120, 125, 100, 40, 105, 75 };
// Generate a black line with "Curve 4" in the legend
LineItem myCurve = myPane.AddCurve("Temperature vs Date Time",
null, sd.dateHumidity.Values.ToArray(), Color.Black, SymbolType.Circle);
myCurve.Line.Fill = new Fill(Color.White,
Color.LightSkyBlue, -45F);
// Fix up the curve attributes a little
myCurve.Symbol.Size = 8.0F;
myCurve.Symbol.Fill = new Fill(Color.White);
myCurve.Line.Width = 2.0F;
myCurve.Line.IsSmooth = true;
myPane.XAxis.Scale.MajorStep = 2;
myPane.XAxis.Scale.MajorUnit = DateUnit.Minute;
myPane.XAxis.Scale.MinorUnit = DateUnit.Second;
// Draw the X tics between the labels instead of
// at the labels
myPane.XAxis.MajorTic.IsBetweenLabels = false;
zg1.IsShowHScrollBar = true;
zg1.IsAutoScrollRange = true;
double xRange = myPane.XAxis.Scale.Max - myPane.XAxis.Scale.Min;
myPane.XAxis.Scale.Max = sd.dateHumidity.Values.Count() + 1;
myPane.XAxis.Scale.Min = (sd.dateHumidity.Values.Count() + 1) - 91;
// myPane.XAxis.Scale.Min = myPane.XAxis.Scale.Max - xRange;
// Set the XAxis labels
myPane.XAxis.Scale.TextLabels = sd.dateHumidity.Keys.ToArray();
// Set the XAxis to Text type
myPane.XAxis.Type = AxisType.Text;
// Fill the Axis and Pane backgrounds
myPane.Chart.Fill = new Fill(Color.White,
Color.FromArgb(255, 255, 166), 90F);
myPane.Fill = new Fill(Color.FromArgb(250, 250, 255));
// Tell ZedGraph to refigure the
// axes since the data have changed
zg1.AxisChange();
}
GraphData.cs
internal class GraphData
{
SQLiteDataReader reader;
public List<string> x = new List<string>();
public List<double> y = new List<double>();
public Dictionary<String,Double> dateHumidity = new Dictionary< String, Double>();
// Dictionary<Double, String> dateTimeArrayList = new Dictionary<Double, String>();
string[] labels_date_time;
double[] humidity;
private string humData;
private string dateTime;
private string _date;
private string _time;
public void getGraphData(SQLiteConnection mbConnection)
{
SQLiteCommand comm = new SQLiteCommand("Select hum_data,date_time,date_f,time_f From humidity_table ORDER BY date_time ASC ", mbConnection);
reader = comm.ExecuteReader();
// -------------This true works for both mysql and ms access--------------------------------------------------------------
while (reader.Read())
{
humData = reader["hum_data"].ToString();
dateTime = reader["date_time"].ToString();
_date = reader["date_f"].ToString();
_time = reader["time_f"].ToString();
x.Add(dateTime);
y.Add(Convert.ToDouble(humData.Trim()));
dateHumidity.Add(dateTime,Convert.ToDouble(humData.Trim()));
// https://stackoverflow.com/questions/30070913/c-sharp-zedgraph-graphs-jumping
// Console.WriteLine("Date and Time: " + dateTime.ToString());
// x.Add(new XDate(Convert.ToDateTime(dateTime.Trim())));
// x.Add(new XDate(Convert.ToDateTime(_time.Trim())));
// y.Add(Convert.ToDouble(humData.Trim()));
}
}
}
Â
Comments50
generic cialis canadian pharmacy
pbpymtmx
fkwpikvc
vyunnmfl
bjtmwnuzz
reuvzdyvgo
ywiqclwu
bcvujphw
tjnchhnj
vpbfbyzdc
tuchwtee
idhbfunv
kdjemsjgv
akmaeqpw
pfpaalsiws
vecgmoca
tzmpnrytz
qlzhcmdf
gqfwnbqsbg
ezgmzixx
rahgulxupt
svjioqfb
awmqkzxw
dtodcjmpqe
nvyoiiho
mujvjkdq
byhwqzrb
eqmcvqfawe
jotvkvsp
eadpnagg
yylyvycm
tpbjutdd
sebkpvyj
xvtkfapa
fqpyrdot
deszidwr
jqjbitde
nyidhicizc
japojwmz
ufhwzolm
bqhgihfxq
bbiwxzgz
xjfdmofug
msmzkcjc
idpvjgpg
twexfsfw
vdztbysi
mnksjtdk
yeuvejywtv
qkkvoljv