Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
45
How to put the value of datachart into label?
posted

We want to put the value of datachart (circle frame) into label (rectangle frame).

The value is from datachart's lineseries tooltip.
Is there any way can put the value into label?

Thank you.

Parents
No Data
Reply
  • 960
    Offline posted

    Hello Chen Alice,

    Seeing your screenshot, it seems that you are using Crosshair, is this correct?

    In that case, you can get the Crosshair point from xamDataChart's CrosshairPoint property. And then, get the series object you want to display the values from chart's Series property and get the data item nearest to the Crosshair point by calling series' GetItem method. The event to do this imelementation would be chart's MouseMove event.

    private void xamDataChart1_MouseMove(object sender, MouseEventArgs e)
    {
        // Get the sender chart instant
        XamDataChart chart = sender as XamDataChart;
    
        // Get the world coordinate of the Crosshair
        Point crosshairPoint = chart.CrosshairPoint;
        if (Double.IsNaN(crosshairPoint.X) || Double.IsNaN(crosshairPoint.Y))
        {
            return;
        }
    
        // Get the "lineSeries1"
        Series series = chart.Series.FirstOrDefault(s => s.Name == "lineSeries1");
        if (series == null)
        {
            return;
        }
    
        // Get the data item nearest to the Crosshair
        DataPoint dataPoint = series.GetItem(crosshairPoint) as DataPoint;  // Cast to the class of your data model.
        // If we get it
        if (dataPoint != null)
        {
            // Update the textboxes with the data item values.
            // NOTE: Format the values by yourself if necessary.
            textBlockLine1X.Text = dataPoint.XValue.ToString();
            textBlockLine1Y.Text = dataPoint.YValue.ToString();
        }
    }

    I attached a sample which use the above codes for your reference.

    3527.F121987-SampleApp1.zip

Children
No Data