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;
}
}
Hi I'm following up to see if anyone has seen this?
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.
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
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.