开发者

MS Chart, X axis dates and cursor interaction when X value is indexed

Good afternoon,

Wow what a title.

Basically here is the thing.

If have a time series which is not continuous.

Hence, since I use the IsXValueIndexed property of the Series (set to true) to collapse the space between the separate points.

That works fine, however I would now like to be able to recover a point's detail in from the graph (X and Y values) and display them in a label on the form.

Hence, I use the following event:

void myChart_CursorPositionChanging(object sender, CursorEventArgs e)
    {
        if (!double.IsNaN(e.NewPosition))
开发者_运维百科        {
            if (e.Axis.AxisName == AxisName.X)
            {
                lbl_selDate.Content = DateTime.FromOADate(e.NewPosition);
            }
            else
            {
                lbl_selValue.Content = e.NewPosition;
            }
        }
    }

The problem is that the date is incorrect... I cannot find the right conversion method to recover this damned timestamp.

Can you by any chance help me out?

Thanks!

Jeremie


suppose you have x-axis of type DateTime then use:

DateTime xValue = DateTime.FromOADate(((Chart)sender).Series[0].Points[(int)e.NewPosition - 1].XValue)

suppose you have y-axis of type double then use:

double yValue = ((Chart)sender).Series[0].Points[(int)e.NewPosition - 1].YValues[0];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜