Formatting chart values using Syncfusion for Xamarin Forms

Asked

Viewed 277 times

4

I’m using the Syncfusion to create graphics in Xamarin Forms.

Studying the documentation, I could not find a way to format the values of my chart, example:

inserir a descrição da imagem aqui

I want these values formatted for Brazilian currency : October - R$ 14,421,52

Does anyone know how I can do it?

My page in XAML:

<chart:SfChart.Series>
    <chart:BarSeries ItemsSource="{Binding PieSeriesData}" Color="Red" XBindingPath="Name" YBindingPath="Value" LegendIcon="Rectangle" Label="Valor (R$)" EnableAnimation="True">
        <chart:BarSeries.DataMarker>
            <chart:ChartDataMarker LabelContent="YValue" ShowLabel="True">
                <chart:DataMarkerLabelStyle LabelFormat="R$##,##" LabelPosition="Center"/>
            </chart:ChartDataMarker>
        </chart:BarSeries.DataMarker>
    </chart:BarSeries>
</chart:SfChart.Series>

1 answer

1


In contact with the support of Syncfusion:

You can reach this requirement by setting a Datatemplate with a Ivalueconvert to data marker and using property Chartdatamarker.LabelTemplate. See the following code snippet for more details.

Datetemplate:

<ResourceDictionary >    
 <local: DataMarkerConverter x:Key="labelConverter"></local: DataMarkerConverter>     
  <DataTemplate x:Key="LabelTemplate">     
    <StackLayout>    
        <Label Text="{Binding YValue, Converter={StaticResource labelConverter}"/>     
    </StackLayout>    
  </DataTemplate>    
</ResourceDictionary>    

Converter:

public class DataMarkerConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        double yValue = System.Convert.ToDouble(value);
        return yValue.ToString("#,###.##", new CultureInfo("pt-BR"));
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return value;
    }
}
  • 3

    It would be interesting for you to share the answer with the community if you found one. Sharing only one link requires that the external content is available, in fact, in this case inclusive, requires authentication (registration on the site) and possibly will only be visible to you, who recorded the incident.

  • 1

    This reply implies login. You can add to the reply what was said on that link?

  • I will prepare and improve that answer. by tomorrow 29-10-17 will already be available a more detailed answer on this subject, thanks for the feedback.

  • @samuelrvg managed to write the most detailed answer?

  • 1

    Sorry, I forgot, I’ll do it now and post.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.