FlexChart DataLabel custom Format

Posted by: david.cunningham on 1 February 2021, 1:46 am EST

  • Posted 1 February 2021, 1:46 am EST

    Hello,

    i need to format my Datalabel on my FlexChart DataLabel:

    <c1:FlexChart.DataLabel>
    <c1:ChartDataLabel
    Position="Bottom"
    Angle="90"
    Content="{}{y}"/>
    </c1:FlexChart.DataLabel>

    My y Value is an int for the number of Operation Seconds which is really high and has to be formatted so that it's human readable with months day seconds etc.
    How can i do so?

    Kind Regards
    David
  • Replied 1 February 2021, 11:30 pm EST

    Hi David

    To achieve this capture the "LabelLoading" event of AxisY of the FlexrGrid.
      Convert the Seconds of your data into the TimeSpan.
      Convert the timeSpan into the DateTime.
      Create a new Label and set the datetime as the text of the label.
      Assign this label to the Label property of the "AxisLabelLoadingEventArgs".


     private void AxisY_LabelLoading(object sender, AxisLabelLoadingEventArgs e)
    {
    Label label = new Label();
    TimeSpan t = TimeSpan.FromSeconds(_list[e.Index].Expenses);
    DateTime dateTime = DateTime.Now + t;
    label.Text = dateTime.ToShortDateString();
    e.Label = label;
    }


    For reference please have a look at the "GettingStartedSample" sample of the attached FlexGrid101 sample.

    Please let me know if you need any other help.

    ThanksFlexChart101.zip
  • Replied 2 February 2021, 1:39 am EST

    Hello Abhishek,

    i made it exactly like in the attached Example but the LabelLoading event isn't firing for any reason.
    Also tried to update but still it doesn't fire t he event.

    And please don't get me wrong, i want to format the datalabel wich is the value on the bar, not the axis label text.

    Kind regards,
    david
  • Replied 2 February 2021, 1:29 am EST

    Hi David

    Can you please try updating to the latest version of the C1Xamarin(4.8.20203.495), and try executing your project?

    If you still face any issue(with the latest build of C1Xamarin), please share a small sample replicating the issue that will help us to assist you better.

    Please let me know if you need any other help.

    Thanks
  • Replied 2 February 2021, 1:41 am EST

    Hello Abhishek,

    I updated to the latest version but it doesn't fire the event.

    And please don't get me wrong, i want to format the datalabel wich is the value on the bar, not the axis label text.
  • Replied 3 February 2021, 7:54 pm EST

    Hello Abhishek,

    i'm still trying to achieve a custom DataLabel and found the following Event:

    this.chart.DataLabelsLoading += chart_DataLabelsLoading;

    private void chart_DataLabelsLoading(object sender, DataLabelLoadingEventArgs e)
    {
    Label label = new Label();
    label.Text = secondsToHumanReadable((int)e.DataPoint.DataY);
    e.View = label;
    }

    The method is getting invoked but unfortunately the label isn't showing in the Diagram.
    I tried settings Position and Align but it didn't work.
    I am on the newest version of c1Xamarin.
    What am i doing wrong?

    Kind regards
    David
  • Replied 4 February 2021, 2:20 am EST

    Hi David

    I can observe this behavior with the ".DataLabelsLoading" event of the FlexChart, I am confirming this behavior with the concerned team. I will let you know as soon as I get any update from them.

    Please let me know if you need any other help.

    Thanks
  • Replied 4 February 2021, 3:10 am EST

    Thanks! I'm looking forward to it!
    I think the TooltipIsLoading also doesn't get executed.
  • Replied 7 February 2021, 9:51 pm EST

    Hi David

    Thanks for sharing this information with us, I am able to replicate the ToolTipLoading issue at my end, I have escalated it to the concerned team. I will let you know as soon as I get any update from them.

    Please let me know if you need any other help.

    Thanks
  • Replied 31 March 2021, 8:59 pm EST

    abhishek.tayal said:
    Hi David

    Thanks for sharing this information with us, I am able to replicate the ToolTipLoading issue at my end, I have escalated it to the concerned team. I will let you know as soon as I get any update from them.

    Please let me know if you need any other help.

    Thanks


    Hello,

    are there any new Information regarding the issue?

    Kind regards
    David
  • Replied 4 April 2021, 11:55 pm EST

    Hi David

    It seems that this event is not handled properly in Xamarin yet. Dev team is looking into this further if it can be handled accordingly.

    I will let you know as soon as I get any update from them.

    Please let me know if you need any other help.

    Thanks
  • Replied 5 April 2021, 7:02 pm EST

    Hi David

    I discussed this with the dev team, To use the TooltipLoading event, we need to set a custom tooltip control. Below is the sample code:

    //Declare global variable
    C1.Xamarin.Forms.Chart.ChartTooltip customTooltip = null;

    //Assign tooltip control
    customTooltip = new C1.Xamarin.Forms.Chart.ChartTooltip();
    flexChart.ToolTip = customTooltip;
    flexChart.ToolTipLoading += FlexChart_ToolTipLoading;

    //Catch the event and handle customization
    private void FlexChart_ToolTipLoading(object sender, C1.Xamarin.Forms.Chart.ChartTooltipLoadingEventArgs e)
    {
    customTooltip.Background = new SolidColorBrush(Color.Red);
    customTooltip.Content = new Label() { Text = "Test text", TextColor = Color.Black };
    }



    Please let me know if you need any other help.

    Thanks
  • Replied 6 April 2021, 4:37 pm EST

    Hi David

    The issue of the view not getting updated in DataLabelsLoading event is fixed by the dev team with the latest build of C1Xamarin, you can get it from nuget.org.

    Please let me know if you need any other help.

    Thanks
  • Replied 19 April 2021, 1:59 am EST

    Hello,
    thanks for your reply!
    Sadly i still need help with integrating. I try to add it but as soon as i try to rotate the view, the label gets lost.This is my code:

    private void chart_DataLabelsLoading(object sender, DataLabelLoadingEventArgs e)
    {
    var StackLayout = new StackLayout();
    StackLayout.BackgroundColor = Color.Green;
    Label label = new Label();
    label.Text = secondsToHumanReadable((int)e.DataPoint.DataY, false);
    label.Rotation = -90;
    //StackLayout.Children.Add(label);
    //StackLayout.Rotation = -90;
    e.View = label;

    }

    Also when zooming in, the view doesn't move..

    Kind regards
    David
  • Replied 19 April 2021, 6:26 pm EST

    Hi David

    Thanks for providing the detailed information, I am able to replicate the issue at my end. I have escalated the issue to the concerned team(with internal tracking Id: 14161) and will let you know as soon as I get any update from them.

    Please let me know if you need any other help.

    Thanks
Need extra support?

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

Learn More

Forum Channels