Display a datetime data label

Hello,

We're migrating a xamarin app to maui and facing the following issue: since the maui charts allow only numeric y-axis, we're using the following approach to plot date-time values: https://support.syncfusion.com/kb/article/12133/how-to-plot-date-time-values-in-vertical-axes-in-net-maui-chart-sfcartesianchart


The question is how to display a data label in this case? In Xamarin we used to use DataMarkerLabelCreated event to do all sorts of manipulations, but apparently this event doesn't exist in maui (yet?).


Kind regards,

Valeriy


3 Replies

SS Sowndharya Selladurai Syncfusion Team November 24, 2023 10:51 AM UTC

Hi Valeriy,

We would like to inform you that the .NET MAUI chart currently does not have support for data label created event or template customization support. However, we have already considered it as a feature request and added it to our feature request list. You can track the status of this feature from the feedback link below.


Feedback link: https://www.syncfusion.com/feedback/38570/support-for-data-label-item-templates-in-net-maui-chart


if you expect to modify the datalabel content, it will be possible by series members, please check the below.


public class ColumnSeriesExt : ColumnSeries

{

    protected override void DrawDataLabel(ICanvas canvas, Brush? fillcolor, string label, PointF point, int index)

    {

        var items = ItemsSource as ObservableCollection<Person>;

        if (items != null)

        {

            var text = items[index].Name ?? "";

            base.DrawDataLabel(canvas, new SolidColorBrush(Colors.Transparent), label, point, index);

            base.DrawDataLabel(canvas, new SolidColorBrush(Colors.Transparent), text, new PointF(point.X, point.Y - 30), index);

        }

    }

}


<model:ColumnSeriesExt ShowDataLabels="True"

                     ItemsSource="{Binding Data}"

                     XBindingPath="Name"

                     YBindingPath="Height">

     <model:ColumnSeriesExt.DataLabelSettings>

         <chart:CartesianDataLabelSettings UseSeriesPalette="False" LabelPlacement="Outer">

             <chart:CartesianDataLabelSettings.LabelStyle>

                 <chart:ChartDataLabelStyle TextColor="Black" FontSize="16" LabelFormat="0'cm"/>

             </chart:CartesianDataLabelSettings.LabelStyle>

         </chart:CartesianDataLabelSettings>

     </model:ColumnSeriesExt.DataLabelSettings>

 </model:ColumnSeriesExt>


Output:

I hope this helps! If you need further assistance, feel free to ask. Thank you.



Regards,

Sowndharya.



VK Valeriy Kovalenko November 27, 2023 12:25 PM UTC

Thank you!


Kind regards,

Valeriy



PR Preethi Rajakandham Syncfusion Team November 28, 2023 04:48 AM UTC

Hi Valeriy,

You're welcome. 

Please let us know if you need further assistance. As always, we are happy to help you out.

Regards,

Preethi R


Loader.
Up arrow icon