日期:2014-05-20 浏览次数:20720 次
//绑定数据源
chart1.DataSource = dataTable;
//X轴---dataTable中是day字段,实际这里是小时
chart1.Series[0].XValueMember = "date";
//Y轴
chart1.Series[0].YValueMembers = "length";
private void chart1_MouseDoubleClick(object sender, MouseEventArgs e)
{
// Call Hit Test Method
HitTestResult result = chart1.HitTest(e.X, e.Y);
if (result.ChartElementType == ChartElementType.DataPoint)
{
DataPoint selectedDataPoint = (DataPoint)result.Object;
MessageBox.Show("X 值:" +selectedDataPoint.XValue + " Y 值: " + selectedDataPoint.YValues[0]);
}
else if (result.ChartElementType != ChartElementType.Nothing)
{
string elementType = result.ChartElementType.ToString();
MessageBox.Show(this, "Selected Element is: " + elementType);
}
}
for (int i = 0; i < 20;i++)
{
chart1.Series["length"].Points.AddXY(date[i], length[i]);
}