C#图表XValue是空的

时间:2014-07-03 10:36:13

标签: c# charts xvalue

我在获取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是空的很奇怪。有没有人有任何想法?

0 个答案:

没有答案