Sunnyui画曲线溢出错误

之前用sunnyui做展示数据库数据曲线的时候、偶然会报溢出错误,也不报错错误在哪,就是直接程序都跑不动了。
image

后面发现
image
设置曲线上下限的时候,当上下限一样的时候就会导致溢出错误、sunnyui的曲线也没有对其抛出异常

对其maxTime和minTime进行数据处理就能解决这个问题了
image

曲线就可以正常绘制了

private void writetime_Tick(object sender, EventArgs e)
{
select_t();
if (Con.State == System.Data.ConnectionState.Closed)
{
Con.Open();
// 连接已打开后的操作
}
foreach (var i in lines)
{
SqlDataAdapter cm = new SqlDataAdapter($"select Temperature,Machine,Time from UT_TemperatureControl where Machine='{i.Name}' ", Con);//and DATEDIFF(day,Time,GETDATE())=0
//SqlCommand b = new SqlCommand($"select count(*) from tt where Machine={i.Name}", Con);
//int k=(int)b.ExecuteScalar();
SqlCommand firstRecordCmd = new SqlCommand("SELECT TOP 1 Time FROM UT_TemperatureControl ORDER BY Time ASC", Con);//where DATEDIFF(day,Time,GETDATE())=0
SqlCommand lastRecordCmd = new SqlCommand("SELECT TOP 1 Time FROM UT_TemperatureControl ORDER BY Time DESC", Con);//where DATEDIFF(day,Time,GETDATE())=0
object firstRecordTimeObj = firstRecordCmd.ExecuteScalar();
object lastRecordTimeObj = lastRecordCmd.ExecuteScalar();
DateTime minTime;
DateTime maxTime;
if (firstRecordTimeObj != null && firstRecordTimeObj != DBNull.Value)
{
if (Convert.ToDateTime(firstRecordTimeObj) == Convert.ToDateTime(lastRecordTimeObj))
{
minTime = Convert.ToDateTime(firstRecordTimeObj).AddHours(-1);
maxTime = Convert.ToDateTime(lastRecordTimeObj).AddHours(1);
}
else
{
minTime = Convert.ToDateTime(firstRecordTimeObj);
maxTime = Convert.ToDateTime(lastRecordTimeObj);
}
}
else
{
// 处理无记录的情况,设置一个默认的最小时间,或者抛出异常,根据实际情况决定
minTime = DateTime.MinValue;
maxTime = DateTime.Now;
}
float temperature = 0.0f;
DateTime currentTime = DateTime.Now;
//double ctime = currentTime.Ticks;
DataTable dt = new DataTable();
cm.Fill(dt);
//var line = historylc.Option.AddSeries(new UILineSeries(i.Name));
historylc.Option.Clear(i.Name);
foreach (DataRow row in dt.Rows)
{
foreach (DataColumn col in dt.Columns)
{
if (col.ColumnName == "Temperature")
{
temperature = Convert.ToSingle(row["Temperature"]);
}
// temperature = (float)row["Temperature"];
if (col.ColumnName == "Time")
{
currentTime = Convert.ToDateTime(row["Time"]);
//string cc = currentTime.ToString("HHmmss");
//ctime = cc.ToDouble();
}
}
historylc.Option.XAxis.SetRange(minTime, maxTime);
historylc.Option.AddData(i.Name, currentTime, temperature);//创建线
//line.Add(currentTime, temperature);
}
}
historylc.Refresh();
if (Con.State == System.Data.ConnectionState.Open)
{
// 连接已打开,进行操作
// ...
Con.Close();
// 连接已关闭后的操作
}
}
posted @   咸鱼过海  阅读(157)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· .NET周刊【3月第1期 2025-03-02】
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
点击右上角即可分享
微信分享提示