This is a migrated thread and some comments may be shown as answers.
Xamarin Android RadLegend View issue.
0 Answers 18 Views
This is a migrated thread and some comments may be shown as answers.
Антон
Top achievements
Rank 1
Антон asked on 27 Dec 2017, 02:37 PM
Hi!

I use RadLegendView to display legend for RadCartesianChartView. I want to use my own colors for charts instead of default. Lines get color as expected and looks very great, but legend still display default color. Looks like I miss something important. Here is my code snippet. Hope to hear from you soon.
01.if (DataSeries != null && DataSeries.Any())
02.{
03.    chart = new RadCartesianChartView(context);
04.    var customPalette = chart.Palette.ClonePalette();
05.    legend= new RadLegendView(context);
06.                    chartName = new TextView(context);
07.    chartName.Text = Name;
08.    chartName.Gravity = GravityFlags.Center;
09.     
10.    // Axis
11.    var verticalAxis = new LinearAxis();
12.    verticalAxis.LabelFormat = VerticalAxisLabelFormat;
13.    var horizontalAxis = new CategoricalAxis();
14.    horizontalAxis.LabelFormat = HorizontalAxisLabelFormat;
15.    chart.VerticalAxis = verticalAxis;
16.    chart.HorizontalAxis = horizontalAxis;
17. 
18.    // Data
19.    foreach (var item in DataSeries)
20.    {
21.        var lineSeries = new LineSeries();
22.        lineSeries.ValueBinding = new ValueBinding();
23.        lineSeries.CategoryBinding = new CategoryBinding();
24.        lineSeries.Data = GetData(item.Key);
25. 
26.        if (!string.IsNullOrEmpty(item.Value?.Color))
27.        {
28.            int color = Color.ParseColor(item.Value.Color);
29.            var chartEntry = customPalette.GetEntry(ChartPalette.LineFamily, item.Key);
30.            chartEntry.Fill = color;
31.            lineSeries.StrokeColor = color;
32.        }
33.        if (item.Value != null && item.Value.LineWidth > 0)
34.        {
35.            lineSeries.StrokeThickness = item.Value.LineWidth;
36.        }
37.        if (!string.IsNullOrEmpty(item.Value?.Name))
38.        {
39.            lineSeries.LegendTitle = item.Value?.Name;
40.        }
41.        chart.Series.Add(lineSeries);
42.    }
43. 
44.    chart.Palette = customPalette;
45.    legend.LegendProvider = chart;
46.    AddView(chartName);
47.    AddView(legend);
48.    AddView(chart);

No answers yet. Maybe you can help?

Tags
Chart
Asked by
Антон
Top achievements
Rank 1
Share this question
or