Legend Icon Colors

When the charts color palette is changed the legends icons colors does not update to the new color palette.


<Page
    x:Class="App2.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:App2"
    xmlns:chart="using:Syncfusion.UI.Xaml.Charts"  ManipulationMode="All"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">
    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"  Margin="10">
        <Grid.DataContext>
            <local:ViewModel/>
        </Grid.DataContext>
        <StackPanel>
            <ComboBox SelectedItem="{x:Bind settings.SelectedChartColorPalette, Mode=TwoWay}" ItemsSource="{x:Bind settings.PaletteList, Mode=OneWay}" >
               
            </ComboBox>
            <chart:SfChart x:Name="chart" Palette="{x:Bind settings.SelectedChartColorPalette, Mode=OneWay }">
            <chart:SfChart.Legend>
                <chart:ChartLegend >
                    <chart:ChartLegend.ItemsPanel>
                        <ItemsPanelTemplate>
                            <ItemsWrapGrid Orientation="Horizontal" Width="Auto"   Name="itemwrap"/>
                        </ItemsPanelTemplate>
                    </chart:ChartLegend.ItemsPanel>
                </chart:ChartLegend>
            </chart:SfChart.Legend>
            <chart:SfChart.PrimaryAxis>
                <chart:CategoryAxis />
            </chart:SfChart.PrimaryAxis>
            <chart:SfChart.SecondaryAxis>
                <chart:NumericalAxis/>
            </chart:SfChart.SecondaryAxis>
                <chart:ColumnSeries XBindingPath="XValue" YBindingPath="YValue" Label="Column series Legend icon not Changing color"
                                ItemsSource="{Binding Data}" SegmentSpacing="10.5" />
                <chart:LineSeries XBindingPath="XValue" YBindingPath="YValue" Label="Line series Legend icon not Changing color"
                                ItemsSource="{Binding Data}" />
            </chart:SfChart>
        </StackPanel>
    </Grid>
</Page>

using Syncfusion.UI.Xaml.Charts;
using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using Windows.UI.Xaml.Controls;
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
namespace App2
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MainPage : Page
    {
        UCChartSettingsViewModel settings = new UCChartSettingsViewModel();
        public MainPage()
        {
            this.InitializeComponent();
        }
    }
    public class Model
    {
        public double XValue { get; set; }
        public double YValue { get; set; }
        public Model(double x,double y)
        {
            XValue = x;
            YValue = y;
        }
    }
    public class ViewModel
    {
       
        public ViewModel()
        {
            Data = new ObservableCollection<Model>();
            Random rd = new Random();
            for (int i = 0; i < 10; i++)
            {
                Data.Add(new Model(i, rd.Next(0, 100)));
            }
        }
        public ObservableCollection<Model> Data { get; set; }
    }

    public class UCChartSettingsViewModel : INotifyPropertyChanged
    {
        private ChartColorPalette selectedColourPalette = new ChartColorPalette();
        public event PropertyChangedEventHandler PropertyChanged;
        public UCChartSettingsViewModel()
        {
            this.PaletteList = new ObservableCollection<ChartColorPalette>();
            PaletteList.Add(ChartColorPalette.Metro);
            PaletteList.Add(ChartColorPalette.AutumnBrights);
            PaletteList.Add(ChartColorPalette.FloraHues);
            PaletteList.Add(ChartColorPalette.Pineapple);
            PaletteList.Add(ChartColorPalette.TomatoSpectrum);
            PaletteList.Add(ChartColorPalette.RedChrome);
            PaletteList.Add(ChartColorPalette.BlueChrome);
            PaletteList.Add(ChartColorPalette.PurpleChrome);
            PaletteList.Add(ChartColorPalette.GreenChrome);
            PaletteList.Add(ChartColorPalette.Elite);
            PaletteList.Add(ChartColorPalette.LightCandy);
            PaletteList.Add(ChartColorPalette.SandyBeach);
            selectedColourPalette = PaletteList[0];
        }
        public ObservableCollection<ChartColorPalette> PaletteList
        {
            get;
            set;
        }
        public ChartColorPalette SelectedChartColorPalette
        {
            get => selectedColourPalette;
            set
            {
                if (selectedColourPalette != value)
                {
                    selectedColourPalette = value;
                    NotifyPropertyChanged();
                }
            }
        }
        private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
}

Attachment: App2_cea52bd.zip

1 Reply

MK Muneesh Kumar G Syncfusion Team August 16, 2018 11:04 AM UTC

Hi Hussein, 
 
Greetings from Syncfusion, we have analyzed your query and you can resolve this problem by using VariableSizedWrapGrid instead of ItemsWrapGrid in legend’s ItemsPanel as per the below code snippet.  
 
Code snippet [XAML]: 
<chart:SfChart.Legend> 
                <chart:ChartLegend > 
                        <chart:ChartLegend.ItemsPanel> 
                            <ItemsPanelTemplate> 
                                <VariableSizedWrapGrid Orientation="Horizontal" Width="Auto"   Name="itemwrap"/> 
                            </ItemsPanelTemplate> 
                        </chart:ChartLegend.ItemsPanel> 
 
                    </chart:ChartLegend> 
            </chart:SfChart.Legend> 
 
We have modified your sample based on this, please find the sample from the following location.  
 
 
You can fit the items in legend using this VariableSizedWrapGrid panel. Please find the output for VariableSizedWrapGrid with more items.  
 
 
Please refer below user documentation for more details about VariableSizedWrapGrid.  
 
 
Hope this helps.  
 
Regards,
Muneesh Kumar G 


Loader.
Up arrow icon