Customize "No Data" message in RadCartesianChartView

4 posts, 0 answers
  1. Ilya
    Ilya avatar
    3 posts
    Member since:
    Oct 2017

    Posted 18 May Link to this post

    Hi!

    I'm using RadCartesianChartView in my Xamarin.Android project. When there are no data to display I see "No Data" message. How can i customize it? I need to change text and textcolor for this message.
  2. Stefan Nenchev
    Admin
    Stefan Nenchev avatar
    639 posts

    Posted 22 May Link to this post

    Hello, Ilya,

    You can directly set the EmptyContent property of the Chart to a string of your choice. I am here adding example on how to do it in a custom renderer for the Xamarin.Forms chart:

    [assembly: Xamarin.Forms.ExportRenderer(typeof(Telerik.XamarinForms.Chart.RadCartesianChart), typeof(CustomChartRenderer))]
    namespace DottedSeriesTest.Droid.CustomRenderers
    {
        public class CustomChartRenderer : CartesianChartRenderer
        {
            protected override void OnElementChanged(ElementChangedEventArgs<RadCartesianChart> e)
            {
                base.OnElementChanged(e);
                this.Control.EmptyContent = "Your text or leave empty";
            }
        }
    }

    As "this.Control" is basically the RadCartesianChartView, you can also directly set it to the instance of the RadCartesianChartView that you have created.

    Have a great rest of the week.

    Regards,
    Stefan Nenchev
    Progress Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. Ilya
    Ilya avatar
    3 posts
    Member since:
    Oct 2017

    Posted 22 May in reply to Stefan Nenchev Link to this post

    Thanks, Stefan!

    But how can I change its color? Is it possible using RadCartesianChartView control API? Default color is black. I need to change it to white.

    Also the text in EmptyContent property is displayed always (for cases when there is some data too - see attached screenshot). Should we check this manually?

  4. Didi
    Admin
    Didi avatar
    19 posts

    Posted 25 May Link to this post

    Hi Ilya,

    In CartensianChart the visual element inside the Chart is private by default and it can’t be customized. Only the text in the TextView can be changed through a custom renderer.

    What I can suggest you is to use a Label positioned over the Chart and set its Text in case the Chart does not contain any data. In this way you could easily set the TextColor of the "No Data" message. I have prepared a sample example to demonstrate how this would work.

    Please check the following files inside the attached project:
    - ViewModel.cs, StartPage.xaml.cs and StartPage.xaml files in the Portable project

    I hope such an approach would be suitable for you.

    Regards,
    Didi
    Progress Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top