开发者

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

开发者 https://www.devze.com 2023-01-03 07:03 出处:网络
Good afternoon, Wow what a title. Basically here is the thing. If have a time series which is not continuous.

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

精彩评论

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