How to change legend text color

2 posts, 0 answers
  1. Matías
    Matías avatar
    1 posts
    Member since:
    Sep 2016

    Posted 10 Feb 2017 Link to this post


    I'm developing a Xamarin application targeting Android and iOS and I'm having some issues when trying to change chart's legend text color.

    My hunch is that is something related to the palette, but I couldn't figure out where the problem might be.

    Here is part of my code:

    //Create the Chart View
    RadCartesianChartView chart = new RadCartesianChartView(this.Activity);
    chart.Background = new global::Android.Graphics.Drawables.ColorDrawable(Color.White);
    /* Add some behavior here */
    /* Axes and so on */
    var customPalette = new ChartPalette(chart.Palette);
    PaletteEntry linesPalette = customPalette.GetEntry(ChartPalette.LineFamily, 0);
    /* Apply my colors here */
    chart.Palette = customPalette;
    // As there are many series, I iterate through them in order to show them together
    foreach (ScatterPointSeries chartSeries in series)
        chartSeries.XValueBinding = hvb;
        chartSeries.YValueBinding = vvb;               
        chartSeries.CanApplyPalette = false;
        chartSeries.StrokeThickness = 5.0f;
        chartSeries.VerticalAxis = verticalAxis;
        chartSeries.HorizontalAxis = horizontalAxis;
    // Legengs
    var legendView = new RadLegendView(this.Activity);
    legendView.LegendProvider = chart;
    var layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WrapContent, GetLegendsHeight(series.Length));
    layoutParams.SetMargins(5, 5, 5, 5);
    legendView.LayoutParameters = layoutParams;
    // And finally I add both views to the layout


    As you can see in the attached screenshot, legend text is grayed out. I'm expecting to see the text color black.

    Am I missing something?

    Many thanks in advance!


  2. Deyan
    Deyan avatar
    2147 posts

    Posted 15 Feb 2017 Link to this post


    You can use the RadLegendView.setItemViewLayout(int layoutId) method to override the default layout resource used for visualizing legend items. You simply need to provide the needed elements within the new layout for the items to be visualized by specifying the same IDs. Here's the default layout:

    <com.telerik.widget.primitives.legend.RadLegendItemView xmlns:android=""
            android:minHeight="15dp" />
            android:layout_height="wrap_content" />

    I hope this helps.

    Telerik by Progress
    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