[英]C# chart and datetime as X Axis
我使用此代碼在C#4中繪制圖表
Series current = chart1.Series.Add("current");
current.AxisLabel = "current";
current.ChartType = SeriesChartType.Line;
string[] xaxis = ClsPath.dt.AsEnumerable()
.Select(row => row.Field<string>("Time"))
.ToArray();
string[] yaxis1 = ClsPath.dt.AsEnumerable()
.Select(row => row.Field<string>("M_1_CURRENT"))
.ToArray();
int i = 0;
foreach (string s in xaxis)
{
chart1.Series["current"].Points.AddXY(Convert.ToDateTime(s), yaxis1[i++]);
}
chart1.Series["current"].XValueType = ChartValueType.DateTime;
chart1.ChartAreas[0].AxisX.IntervalType = DateTimeIntervalType.Minutes;
chart1.ChartAreas[0].AxisX.Interval = 1;
圖表淹沒而沒有xaxis。 我清除這條線
Series current = chart1.Series.Add("current");
current.AxisLabel = "current";
current.ChartType = SeriesChartType.Line;
string[] xaxis = ClsPath.dt.AsEnumerable()
.Select(row => row.Field<string>("Time"))
.ToArray();
string[] yaxis1 = ClsPath.dt.AsEnumerable()
.Select(row => row.Field<string>("M_1_CURRENT"))
.ToArray();
int i = 0;
foreach (string s in xaxis)
{
chart1.Series["current"].Points.AddXY(s, yaxis1[i++]);
}
現在只顯示兩個xaxis值。 我使用databindxy,它引發了一個錯誤,即Y值無法綁定到字符串對象。 反正有沒有顯示圖表中的所有x值?
PS:我使用DataBindCrossTable(chart1.DataBindCrossTable(dv,“ Time”,“ Time”,“ M_1_CURRENT”,“”);),結果是
你嘗試過這樣的事情嗎? http://msdn.microsoft.com/zh-CN/library/vstudio/dd488514(v=vs.100).aspx
current.DataBindCrossTable(dv, "series", "Time", "M_1_CURRENT", "");
希望這可以幫助!
從msdn頁面
public void DataBindCrossTable(
IEnumerable dataSource,
string seriesGroupByField,
string xField,
string yFields,
string otherFields)
第二個參數應該是與該行的所有數據相同的值,例如此處的相同數據
+--------+------------+-------------+
| series | Time | M_1_CURRENT |
+--------+------------+-------------+
| serie1 | 2013-11-12 | 1 |
| serie1 | 2013-11-13 | 1.5 |
| serie1 | 2013-11-14 | 1.9 |
| serie1 | 2013-11-15 | 1.2 |
+--------+------------+-------------+
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.