This is a migrated thread and some comments may be shown as answers.

How to change legend text color

1 Answer 100 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Matías
Top achievements
Rank 1
Matías asked on 10 Feb 2017, 02:08 PM

Hi,

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;
 
    chart.Series.Add(chartSeries);
}
 
// 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
linearLayout.AddView(legendView);
linearLayout.AddView(chart);

 

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!

 

1 Answer, 1 is accepted

Sort by
0
Deyan
Telerik team
answered on 15 Feb 2017, 01:54 PM
Hello,

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="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
 
    <FrameLayout
        android:id="@+id/legendItemIconView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:minWidth="15dp"
        android:minHeight="15dp" />
 
    <TextView
        android:id="@+id/legendItemTitleView"
        android:layout_gravity="center_vertical"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</com.telerik.widget.primitives.legend.RadLegendItemView>

I hope this helps.

Regards,
Deyan
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
Tags
Chart
Asked by
Matías
Top achievements
Rank 1
Answers by
Deyan
Telerik team
Share this question
or