当它的数字非常小(小于一个)时,我的图表似乎没有显示正确的值。当我有很大的价值(大于一个)时,似乎可以很好地绘制和缩放所有内容。知道我在做什么错吗?
我的图表代码:
private void do_chart_Conc(RunningTests rt, Chart c)
{
c.Series.Clear();
set_chart_alignment(c);
DataTable dt = SQL.get_Conc(rt);
c.DataSource = dt;
Series s = new Series("Conc");
s.XValueMember = "Time_Stamp";
s.YValueMembers = "Conc";
s.ChartType = SeriesChartType.Line;
s.BorderWidth = 2;
s.MarkerSize = 5;
s.MarkerStyle = MarkerStyle.Circle;
s.IsValueShownAsLabel = true;
s.Label = "#VALY{0.0000}";
c.ChartAreas[0].AxisY.IsStartedFromZero = false;
c.ChartAreas[0].AxisX.LabelStyle.Format = "yyyy-MM-dd\nHH:mm:ss";
c.ChartAreas[0].AxisY.LabelStyle.Format = "0.0000";
c.ChartAreas[0].RecalculateAxesScale();
c.Series.Add(s);
c.Legends.Clear();
}
我的SQL代码:
static public DataTable get_Conc(RunningTests rt)
{
DataTable dt = new DataTable();
using (SqlConnection cs = new SqlConnection(connString))
{
string query = string.Empty;
if (rt.StopTime.Ticks > 0)
{
query = string.Format("SELECT Time_Stamp, RawConc FROM Test WHERE Unit_ID = '{0}' AND Time_Stamp > '{1}' AND Time_Stamp < '{2}'", rt.Unit_ID, rt.StartTime.Ticks, rt.StopTime.Ticks);
}
else
{
query = string.Format("SELECT Time_Stamp, RawConc FROM Test WHERE Unit_ID = '{0}' AND Time_Stamp > '{1}'", rt.Unit_ID, rt.StartTime.Ticks);
}
SqlCommand cmd = new SqlCommand(query, cs);
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
da.Fill(dt);
}
}
//Person stored the date time to ticks, have to convert back to DateTime
DataTable dtCloned = new DataTable();
dtCloned.Clear();
dtCloned.Columns.Add("Time_Stamp", typeof(DateTime));
dtCloned.Columns.Add("Conc", typeof(int));
foreach (DataRow dr in dt.Rows)
{
DataRow r = dtCloned.NewRow();
r[0] = new DateTime((long)dr[0]);
r[1] = dr[1];
dtCloned.Rows.Add(r);
}
dtCloned.DefaultView.Sort = "Time_Stamp DESC";
dtCloned = dtCloned.DefaultView.ToTable();
return dtCloned;
}
我希望它绘制出实际值并显示出来(而不是零)。 IE:-0.0021
答案 0 :(得分:1)
由于输入的y值为int
,所以您失去了精度。
更改
dtCloned.Columns.Add("Conc", typeof(int));
到
dtCloned.Columns.Add("Conc", typeof(double));
一切都应该很好。