[英]C# chart and datetime as X Axis
I use this code to draw a chart in C# 4 我使用此代码在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;
chart is drown without xaxis. 图表淹没而没有xaxis。 I clear this lines
我清除这条线
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++]);
}
now it show only two xaxis value. 现在只显示两个xaxis值。 I use databindxy and it raise an error that Y values cannot bind to string object.
我使用databindxy,它引发了一个错误,即Y值无法绑定到字符串对象。 is there anyway to show all x values in chart?
反正有没有显示图表中的所有x值?
PS : I use DataBindCrossTable (chart1.DataBindCrossTable(dv, "Time", "Time", "M_1_CURRENT", "");) and result is PS:我使用DataBindCrossTable(chart1.DataBindCrossTable(dv,“ Time”,“ Time”,“ M_1_CURRENT”,“”);),结果是
Have you tried something like this? 你尝试过这样的事情吗? http://msdn.microsoft.com/en-us/library/vstudio/dd488514(v=vs.100).aspx
http://msdn.microsoft.com/zh-CN/library/vstudio/dd488514(v=vs.100).aspx
current.DataBindCrossTable(dv, "series", "Time", "M_1_CURRENT", "");
Hope this helps! 希望这可以帮助!
from msdn page 从msdn页面
public void DataBindCrossTable(
IEnumerable dataSource,
string seriesGroupByField,
string xField,
string yFields,
string otherFields)
the second parameter should be a value that is the same for all data of the line like the same data here 第二个参数应该是与该行的所有数据相同的值,例如此处的相同数据
+--------+------------+-------------+
| 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.