How can I bind my colors with chart items?

Oct 26, 2013 at 3:50 PM
Edited Oct 26, 2013 at 4:21 PM
public class Part
{
    public Part() { }

    public int Id { get; set; }
    public string Name { get; set; }
    public string Color { get; set; }
    public float Value { get; set; }
    public string Type { get; set; }
}

    <chart:PieChart Grid.Column="0" ChartTitle="Chart Title" ChartSubTitle="Chart Sub Title" SelectedItem="{Binding SelectedItem, Mode=TwoWay}" Background="Transparent">
        <chart:PieChart.Series>
            <chart:ChartSeries SeriesTitle="Series Title" ItemsSource="{Binding Parts}" DisplayMember="Name" ValueMember="Value" Background="Color ????????????????"/>
        </chart:PieChart.Series>
    </chart:PieChart>
Nov 8, 2013 at 2:09 PM
I have also been trying to figure out how to do this, it would be a very useful way of making the colours consistent over a number of different graphs.
Nov 12, 2013 at 3:29 PM
Really? Have you guys even looked at the sample application?

Why aren't you setting the Palette property on the Chart, like in :
<chart:RadialGaugeChart Style="{StaticResource MinimalChartStyle}"
                                            Grid.Column="0"                                           
                                            Palette="{StaticResource OverallChartColors}"                                            
                                            SelectedBrush="Transparent">
You define color palettes and you set them to the charts that you want. This absolutely makes the colors consistent over a number of different graphs. You guys need to look at the source of the sample application.
Nov 12, 2013 at 4:28 PM
Edited Nov 12, 2013 at 4:32 PM
I need a color definition by the user, not Palette.
I have a class:
public class Part
{
    public Part() { }

    public string Name { get; set; }
    public float Value { get; set; }
    public string Color { get; set; }
}
I solved this problem. Thank you.
Nov 12, 2013 at 8:25 PM
so what was your solution?
Dec 7, 2013 at 4:14 PM
Edited Dec 7, 2013 at 4:15 PM
After a lot of pain, I solved in this way:
<UserControl.Resources>
    <conv:ColorConverter x:Key="colorconverter" />
    <!-- colorconverter is a class mean to convert color from string, the converterparam is the default color if NoneColor is null -->
    <SolidColorBrush x:Key="br1" Color="{Binding Source={StaticResource colorsettings}, Path=NoneColor, Converter={StaticResource colorconverter}, ConverterParameter={StaticResource NONE_COLOR} }" />
    <chart:ResourceDictionaryCollection x:Key="colorPalette">            
        <ResourceDictionary>
            <SolidColorBrush x:Key="Brush1" Color="{Binding Source={StaticResource br1}, Path=Color}" />
        </ResourceDictionary>
    </chart:ResourceDictionaryCollection>
</UserControl.Resources>
However I can't figure out why the leading 0 appears :-/
Dec 10, 2013 at 6:33 AM
Edited Dec 10, 2013 at 6:44 AM
flyte wrote:
so what was your solution?
I did something. For me it works. Look..
 
======================================
 
only for PieChart
 
<chart:PieChart x:Name="dpPieChart" Grid.Column="0" Grid.Row="1" ChartTitle="{Binding Title}" ChartSubTitle="{Binding SubTitle}" SelectedItem="{Binding SelectedItem, Mode=TwoWay}" SelectedBrush="#33ffffff" Background="Transparent">
<chart:PieChart.Series>
<chart:ChartSeries SeriesTitle="Series Title" ItemsSource="{Binding Source={StaticResource PartsCollection}}" DisplayMember="Name" ValueMember="ValueIn" 

    ColorMember="ColorBrush"/>

</chart:PieChart.Series>
</chart:PieChart>
 
============================================
 
public class PartViewModel : ViewModelBase
{
public string Color
{
get
{
return _part.Color;
}
set
{
if (_part.Color != value)
{
_part.Color = value;
RaisePropertyChanged("Color");
RaisePropertyChanged("ColorBrush");
}
}
}

public Brush ColorBrush
{
get
{
return StaticFunctions.ColorToBrush(_part.Color);
}
}
 
 
================================================
 
public static class StaticFunctions
{
public static Brush ColorToBrush(string color)
{
color = color.Replace("#", "");
if (color.Length == 8)
{
color = color.Substring(2, 6);
}
if (color.Length == 6)
{
return new SolidColorBrush(ColorHelper.FromArgb(255,
byte.Parse(color.Substring(0, 2), System.Globalization.NumberStyles.HexNumber),
byte.Parse(color.Substring(2, 2), System.Globalization.NumberStyles.HexNumber),
byte.Parse(color.Substring(4, 2), System.Globalization.NumberStyles.HexNumber)));
}
else
{
return null;
}
}
}
dll project in the ZIP:
De.TorstenMandelkow.MetroChart.WinRT.zip - link 1
De.TorstenMandelkow.MetroChart.WinRT.zip - link 2
Jun 12, 2014 at 5:58 AM
Hello Everyone

I m Facing Same Problem in modern ui Chart So can you provide me Some other Example For that issue in Detail.



Thanks in Advanced