我在获取 AxisX 的值时遇到问题。
我添加了新的积分形式dataTable
:
chart1.Series.Add(dataTable.Columns[x].Caption);
chart1.Series[dataTable.Columns[x].Caption].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
chart1.Series[dataTable.Columns[x].Caption].BorderWidth = 1;
for (int i = 0; i < dataTable.Rows.Count - 1; i++)
chart1.Series[dataTable.Columns[x].Caption].Points
.AddXY(dataTable.Rows[i][0], dataTable.Rows[i][x]);
我使用 mouse_move 事件来获取值并在标签中显示它们。
private void chart1_MouseMove(object sender, MouseEventArgs e)
{
Point mousePoint = new Point(e.X, e.Y);
var pos = e.Location;
if (prevPosition.HasValue && pos == prevPosition.Value)
return;
tooltip.RemoveAll();
prevPosition = pos;
var results = chart1.HitTest(pos.X, pos.Y, false,
ChartElementType.DataPoint);
foreach (var result in results)
{
if (result.ChartElementType == ChartElementType.DataPoint)
{
var prop = result.Object as DataPoint;
if (prop != null)
{
tooltip.Show("X=" + DateTime.FromOADate(prop.XValue) + "\n Y=" + prop.YValues[0], this.chart1,
pos.X, pos.Y - 15);
}
}
}
}
奇怪的prop.XValue
是空的。有没有人有任何想法?