We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

FastCandleBitmapSeries TooltipTemplate want to use converter to get XValue but ChartDataPointInfo is inaccessible

Hi,

I was using a solution that combines some suggestions here, whic includes created a class 

LabelFormatConverter : IValueConverter.


Best approach to show labels while passing over candles in chart? | WPF Forums | Syncfusion


I created my data template like this where chart is the name of my SfChart control

<chart:SfChart.Resources>

                <converters:LabelFormatConverter x:Key="formatConverter"/>

                <DataTemplate x:Key="toolTipTemplate">

                    <Border CornerRadius="5" Background="Black">

                        <StackPanel Orientation="Vertical" Margin="5" Grid.IsSharedSizeScope="True">

                            <Grid>

                                <Grid.ColumnDefinitions>

                                    <ColumnDefinition Width="auto" SharedSizeGroup="Col1"/>

                                    <ColumnDefinition Width="auto" SharedSizeGroup="Col2"/>

                                    <ColumnDefinition Width="auto" SharedSizeGroup="Col3"/>

                                </Grid.ColumnDefinitions>

                                <TextBlock Text="Time" FontSize="10" Foreground="White" Grid.Column="0"/>

                                <TextBlock Text=":" FontSize="10" Foreground="White" Padding="2,0,0,0" Grid.Column="1"/>

                                <TextBlock Text="{Binding Converter={StaticResource formatConverter},ConverterParameter={x:Reference chart}}"

                                           FontSize="10" Foreground="White" Padding="2,0,0,0" Grid.Column="2"/>

                            </Grid>

                        </StackPanel>

                    </Border>

                </DataTemplate>


In my chart I have my candle series set up like this.


<chart:FastCandleBitmapSeries x:Name="candleSeries"

                                          ItemsSource="{Binding Path=Bars}"

                                          XBindingPath="Date"

                                          High="High"

                                          Low="Low"

                                          Open="Open"

                                          Close="Close"

                                          BearFillColor="Maroon"

                                          BullFillColor="MidnightBlue"

                                          ShowTooltip="True"

                                          TooltipTemplate="{StaticResource toolTipTemplate}">


And in the link I showed you above, there is an example of setting up LabelFormatConverter : IValueConverter

Below is the original version as in the example from the link. The problem is that the type of value passed is  ChartDataPointInfo which is not accessible, because it is markes as internal.

So how can I convert the x value from the ChartDataPointInfo that is passed from  FastCandleBitmapSeries??


public class LabelFormatConverter : IValueConverter

    {

        //https://www.syncfusion.com/forums/174569/best-approach-to-show-labels-while-passing-over-candles-in-chart

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)

        {

            ChartPointInfo chartPointInfo = (ChartPointInfo)value;

            //ChartDataPointInfo chartPointInfo = (ChartDataPointInfo)value;

            SfChart? chart = parameter as SfChart;

            if (chartPointInfo != null && chart != null)

            {

                var x = chartPointInfo.X;

                var y = chartPointInfo.Y;

                Point point = new(x, y);

                double xValue = chart.PointToValue(chart.PrimaryAxis, point);

                return DateTime.FromOADate(xValue).ToString("yyyy.MM.dd HH:mm");

            }


            return string.Empty;

        }


        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)

        {


            return value;

        }

    }


4 Replies 1 reply marked as answer

LO Lorenzo November 14, 2022 09:35 PM UTC

Hi I'm following up to see if anyone has seen this?



NM Nanthini Mahalingam Syncfusion Team November 15, 2022 01:19 PM UTC

Hi Lorenzo,


We have validated your query, and you can get our ChartSegment in tooltip converter. From the segment instance you can get the underlying model value from the Item property. After you can use the required field from the model instance as per the below code snippet.


public object Convert(object value, Type targetType, object parameter, CultureInfo culture)

        {

            var chartDataPointInfo = (ChartSegment)value;

            CandleChartModel xValue = (CandleChartModel)chartDataPointInfo.Item;

            return xValue.Date.ToString("yyyy.MM.dd HH:mm");

        }

 

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)

        {

            return value;

        }


Regards,

Nanthini.


Marked as answer

LO Lorenzo November 16, 2022 11:39 AM UTC

Ok I understand, I'm casting to the parent class of the ChartDataPointInfo object, which is ChartSegment.

For anyone reading this, 'CandleChartModel' in the example, represents the model for the chart candle and not some other class.

This is a good solution. Thanks



PR Preethi Rajakandham Syncfusion Team November 17, 2022 06:27 AM UTC

We are glad that the provided response meets your requirement. Please let us know if you need further assistance. As always, we are happy to help you out. 


Loader.
Live Chat Icon For mobile
Up arrow icon