WpfChart Custom DataLabels

Posted by: hmmftg on 27 August 2018, 5:53 am EST

    • Post Options:
    • Link

    Posted 27 August 2018, 5:53 am EST

    Hi, I’m using LineSmoothed wpf chart,

    I want to display a performance monitoring chart,

    I’m able to draw the chart and everything is ok as DynamicChart example,

    The below code is my update function:

    
    void Update()
    {
        chart.BeginUpdate();
    
        int cnt = nAddPoints;
        for (int i = 0; i < cnt; i++)
        {
            //My new point gets it's value from here
            double value = rnd.NextDouble();
            if (value > chart.View.AxisY.Max)
            {
                //Detected New Max Value
                chart.View.AxisY.Max = value;
            }
            _pts.Add(new Point(counter++, value));
        }
    
        int ndel = _pts.Count - nMaxPoints;
        if (ndel > 0)
            for (int i = 0; i < ndel; i++)
                _pts.RemoveAt(0);
    
        chart.EndUpdate();
    }
    

    The AxisY max value is updated when I get bigger value than the current max,

    I wanted to add a lable for this new max value to be displayed and noticed

    I tried adding ```

    Datatemplate

    
    
        <c1chart:DataPointConverter x:Key="fc" />
        <DataTemplate x:Key="lbl">
            <Grid>
                <Path Data="M0.5,0.5 L23,0.5 23,23 11.61165,29.286408 0.5,23 z" Stretch="Fill" Fill="#FFF1F1F1" Stroke="DarkGray" StrokeThickness="1" />
                <TextBlock FontSize="10" Margin="5 5 5 15" Foreground="DarkRed" Text="{Binding ConverterParameter=Series: \{#SeriesLabel\}\{#NewLine\}Point: \{#PointIndex\}\{#NewLine\}Value: \{#Value\}, Converter={StaticResource fc}}" />
            </Grid>
        </DataTemplate>
    
    
    when I modify my ```
    XYDataSeries
    ``` and set it's ```
    PointLabelTemplate
    ``` to ```
    (DataTemplate)Resources["lbl"]
    ``` it's displaying the label for all the points and it becomes a mess!
    
    Please help me with this
    Thanks
  • Posted 28 August 2018, 6:14 pm EST

    Hello,

    To get rid of too much DataLabels, you can display label for maximum value point. In order to do so manipulate the visibility of label’s template elements according to data value by specifying an appropriate converter. Please refer the attached sample (prj_CustomDatalabels.zip) for complete implementation.

    Another possibility could be to use an auxiliary Y-axis with its ItemsSource set to array of Min and Max values. You can refer the following link for doing this: https://www.grapecity.com/en/forums/silverlight-edition/how-to-always-display-view

    Please let us know if any of the above methods helps.

    Thank you.

    prj_CustomDataLabels.zip

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels