logo
down
shadow

WPF Toolkit Pie Chart Style Colors


WPF Toolkit Pie Chart Style Colors

By : Steven C.
Date : October 28 2020, 08:00 PM
will be helpful for those in need Not sure if this is the best way of doing it but I struggled with the same thing and eventually got it working like this.
Declare a palette:
code :


Share : facebook icon twitter icon
Silverlight Toolkit ; Pie Chart Colors

Silverlight Toolkit ; Pie Chart Colors


By : user3638177
Date : March 29 2020, 07:55 AM
this one helps. I have found the solution, after much swearing and investigation. There are a lot of moving parts here, so I am going to keep each as brief as possible while still conveying the main points.
For starters I have a collection of objects that I am trying to keep track of:
code :
public class PileOfFruit
{
  public string Name {get; set; }
  public int Count { get; set; }
}
public class BasketVM
{
...
    private ObservableCollection<PileOfFruit> _FruitBasket = new ObservableCollection<PileOfFruit>();
    public ObservableCollection<PileOfFruit> FruitBasket
    {
      get { return _FruitBasket; }
    }
...
}
<chartingToolkit:Chart x:Name="ExampleChart">
    <chartingToolkit:PieSeries ItemsSource={Binding FruitBasket
                               DependentValueBinding="{Binding Count}" 
                               IndependentValueBinding="{Binding Name}">
        <chartingToolkit:PieSeries.Palette>
            <visualizationToolkit:ResourceDictionaryCollection>
            <ResourceDictionary>
                <Style x:Key="DataPointStyle" TargetType="Control">
                    <Setter Property="Template" Value="{StaticResource SliceTemplate}"/>
                </Style>
<converters:FruitToColorConverter x:Key="FruitToColorConverter"/>

<ControlTemplate x:Key="SliceTemplate" TargetType="chart:PieDataPoint">
  <Path Data="{TemplateBinding Geometry}"
        Fill="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=IndependentValue, Converter={StaticResource FruitToColorConverter}}"
        Stroke="{TemplateBinding BorderBrush}">
    ....
public class FruitToColorConverter : IValueConverter
{
  private SolidColorBrush Default = new SolidColorBrush(Colors.Black);

  public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  {
    if (value == null || (!(value is string))) { return Default; }

    switch (value as string)
    {
      case "Apple":
        return new SolidColorBrush(Colors.Red);
      case "BlueBerry":
        return new SolidColorBrush(Colors.Blue);
      default:
        return Default;
        ......
How to change the palette colors of WinRT XAML Toolkit Chart controls?

How to change the palette colors of WinRT XAML Toolkit Chart controls?


By : Akshay Karande
Date : March 29 2020, 07:55 AM
Hope that helps If you search for "Palette" in the source of the toolkit you will see how the default style of the Chart control has a Palette property which is a collection of ResourceDictionary. You can apply it in a similar fashion in your app either as a chart Style or directly as its property, e.g.
code :
<charting:Chart
    x:Name="PieChartWithCustomPalette"
    Title="Pie Chart with Custom Palette"
    Margin="70,0">
    <charting:Chart.Palette>
        <charting:ResourceDictionaryCollection>
            <!-- Blue -->
            <ResourceDictionary>
                <SolidColorBrush
                    x:Key="Background"
                    Color="#4586d8" />
                <Style
                    x:Key="DataPointStyle"
                    TargetType="Control">
                    <Setter
                        Property="Background"
                        Value="{StaticResource Background}" />
                </Style>
                <Style
                    x:Key="DataShapeStyle"
                    TargetType="Shape">
                    <Setter
                        Property="Stroke"
                        Value="{StaticResource Background}" />
                    <Setter
                        Property="StrokeThickness"
                        Value="2" />
                    <Setter
                        Property="StrokeMiterLimit"
                        Value="1" />
                    <Setter
                        Property="Fill"
                        Value="{StaticResource Background}" />
                </Style>
            </ResourceDictionary>
            <!-- Red -->
            <ResourceDictionary>
                <SolidColorBrush
                    x:Key="Background"
                    Color="#dc443f" />
                <Style
                    x:Key="DataPointStyle"
                    TargetType="Control">
                    <Setter
                        Property="Background"
                        Value="{StaticResource Background}" />
                </Style>
                <Style
                    x:Key="DataShapeStyle"
                    TargetType="Shape">
                    <Setter
                        Property="Stroke"
                        Value="{StaticResource Background}" />
                    <Setter
                        Property="StrokeThickness"
                        Value="2" />
                    <Setter
                        Property="StrokeMiterLimit"
                        Value="1" />
                    <Setter
                        Property="Fill"
                        Value="{StaticResource Background}" />
                </Style>
            </ResourceDictionary>
        </charting:ResourceDictionaryCollection>
    </charting:Chart.Palette>
    <charting:Chart.Series>
        <Series:PieSeries
            Title="Population"
            ItemsSource="{Binding Items}"
            IndependentValueBinding="{Binding Name}"
            DependentValueBinding="{Binding Value}"
            IsSelectionEnabled="True" />
    </charting:Chart.Series>
</charting:Chart>
How to give Style to WPF Toolkit Chart

How to give Style to WPF Toolkit Chart


By : shymeck
Date : March 29 2020, 07:55 AM
will be helpful for those in need If you looked at visual tree you find out that you must change Background property of grid and border to change background to transparent (elements highlighted in yellow in the below picture).
code :
<DVC:Chart Canvas.Top="80" Canvas.Left="10" Name="mcChart" 
   Width="400" Height="250"
   Background="Orange"
   Loaded="mcChart_Loaded">            
    <DVC:Chart.Series>
        <DVC:PieSeries Title="Experience" 
            ItemsSource="{StaticResource FruitCollection}"
            IndependentValueBinding="{Binding Path=Name}"
            DependentValueBinding="{Binding Path=Share}">                
        </DVC:PieSeries>
    </DVC:Chart.Series>           
</DVC:Chart>
private void mcChart_Loaded(object sender, RoutedEventArgs e)
{
    EdgePanel ep = VisualHelper.FindChild<EdgePanel>(sender as Chart, "ChartArea");
    if (ep != null)
    {
        var grid = ep.Children.OfType<Grid>().FirstOrDefault();
        if (grid != null)
        {
            grid.Background = new SolidColorBrush(Colors.Transparent);
        }

        var border = ep.Children.OfType<Border>().FirstOrDefault();
        if (border != null)
        {
            border.BorderBrush = new SolidColorBrush(Colors.Transparent);
        }
    }

    Legend legend = VisualHelper.FindChild<Legend>(sender as Chart, "Legend");
    if (legend != null)
    {
        legend.Background = new SolidColorBrush(Colors.Transparent);
        legend.BorderBrush = new SolidColorBrush(Colors.Transparent);               
    }
}
class VisualHelper
{
    public static T FindChild<T>(DependencyObject parent, string childName) where T : DependencyObject
    {
        if (parent == null) return null;

        T foundChild = null;

        int childrenCount = VisualTreeHelper.GetChildrenCount(parent);
        for (int i = 0; i < childrenCount; i++)
        {
            var child = VisualTreeHelper.GetChild(parent, i);
            T childType = child as T;
            if (childType == null)
            {
                foundChild = FindChild<T>(child, childName);
                if (foundChild != null) break;
            }
            else if (!string.IsNullOrEmpty(childName))
            {
                var frameworkElement = child as FrameworkElement;
                if (frameworkElement != null && frameworkElement.Name == childName)
                {
                    foundChild = (T)child;
                    break;
                }
            }
            else
            {
                foundChild = (T)child;
                break;
            }
        }
        return foundChild;
    }
}
Style Active point for Chart ToolKit in WPF

Style Active point for Chart ToolKit in WPF


By : Anuwach Heng
Date : March 29 2020, 07:55 AM
Any of those help You have to create a Style for your Ellipse and handle IsMouseOver and MouseDown event.
XAML:
code :
<Window.Resources>
    <Style x:Key="EllipseStyle1"  TargetType="{x:Type Ellipse}">
        <Setter Property="Fill" Value="Yellow"></Setter>
        <Setter Property="Stroke" Value="Orange"></Setter>
        <Setter Property="Height" Value="12"></Setter>
        <Setter Property="Width" Value="12"></Setter>
        <Style.Triggers>
            <Trigger Property="IsMouseOver" Value="true">
                <Setter Property="StrokeThickness" Value="3"></Setter>
            </Trigger>
        </Style.Triggers>
    </Style>
    <Style x:Key="PolylineStyle1" TargetType="{x:Type Polyline}">
        <Setter Property="StrokeThickness" Value="1"/>
        <Setter Property="Stroke" Value="Blue"></Setter>
    </Style>
    <Style x:Key="DataPointStyle1" TargetType="{x:Type chartingToolkit:LineDataPoint}">
        <Setter Property="Background" Value="Yellow"></Setter>
        <Setter Property="Width" Value="16"></Setter>
        <Setter Property="Height" Value="16"></Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="chartingToolkit:LineDataPoint">
                    <Ellipse Style="{DynamicResource EllipseStyle1}"  MouseDown="Ellipse_MouseDown"/>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    <Style x:Key="LineSeriesStyle1" TargetType="{x:Type chartingToolkit:LineSeries}" >
        <Setter Property="IsTabStop" Value="False"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type chartingToolkit:LineSeries}">
                    <Canvas x:Name="PlotArea">
                        <Polyline Points="{TemplateBinding Points}" Style="{DynamicResource PolylineStyle1}" />
                    </Canvas>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</Window.Resources>

<Grid>
    <chartingToolkit:Chart Margin="0" Title="Chart Title">
        <chartingToolkit:Chart.DataContext>
            <PointCollection>1,10 2,20 3,30 4,40</PointCollection>
        </chartingToolkit:Chart.DataContext>
        <chartingToolkit:LineSeries DependentValuePath="Y" IndependentValuePath="X" 
                                    ItemsSource="{Binding}" IsSelectionEnabled="True"
                                    Style="{DynamicResource LineSeriesStyle1}"
                                    DataPointStyle="{DynamicResource DataPointStyle1}"/>
    </chartingToolkit:Chart>
</Grid>
    private void Ellipse_MouseDown(object sender, MouseButtonEventArgs e)
    {
        curr = (Ellipse)sender;

        if (curr == prev)
        {
            if (curr.Fill == Brushes.Yellow)
                curr.Fill = Brushes.Red;
            else if (curr.Fill == Brushes.Red)
                curr.Fill = Brushes.Yellow;
        }
        else
        {
            if (prev == null)
                prev = curr;

            prev.Fill = Brushes.Yellow;
            curr.Fill = Brushes.Red;
        }
        prev = curr;
    }
WPF Toolkit Chart Axes cannot be set through Style

WPF Toolkit Chart Axes cannot be set through Style


By : Reez Rk Klink
Date : March 29 2020, 07:55 AM
it fixes the issue you're close :)
You have to attach the style to the linearAxis itself, as there is not accessor from the chart style.
Related Posts Related Posts :
  • How to use Selenium Grid with C#?
  • What is the best way to download files via HTTP using .NET?
  • How to get files from a device using USB
  • Given a user's SID, how do I get their userPrincipalName?
  • NHibernate mapping in Asp.Net using MySql
  • Why do some cookies have a '.' before the domain?
  • C# SqlDataReader = null?
  • InvalidCastException for two Objects of the same type
  • "The parameters dictionary contains a null entry for parameter" - How to fix?
  • Font family name from font file
  • What is the best way to generate KML files in C#?
  • How can I receive mail using .NET?
  • How to send raw data over a network?
  • meaning of '+='
  • Object reference not set to an instance of an object #5
  • C# Create "wireframe"/3D "map"
  • How to change size of database
  • Serialization problem
  • Using unmanaged code from managed code
  • Are there any bindings between .NET and TK
  • error with linq join
  • VB.NET equivalent to C# var keyword
  • Accessing object properties from string representations
  • Inheritance issue
  • C# timer won't tick
  • How to retrieve items from a database c#
  • Sending mail using SmtpClient in .net
  • Tag problem c# listbox
  • How to know if the Form App open or not c#
  • C# XPath id() not working?
  • Load PDF from Memory ASP.Net
  • C# ListView with a ProgressBar
  • Getting the right WPF dispatcher in a thread
  • How to create Pivot table using C#?
  • how to download a file from remote server using asp.net
  • Binding files in C#?
  • Copy one object to another
  • How to post on Google Buzz?
  • Generic <T> how cast?
  • Set global hotkeys using C#
  • Change the key being pressed with C#
  • Uploading Large Files
  • How do I get the duration of a video file using C#?
  • how to create instance for a generic type in c#
  • Drag and drop rectangle in C#
  • RSA Encryption C#
  • Title=
  • What is meant by Web Services?
  • The provided URI scheme 'https' is invalid; expected 'http'. Parameter name: via
  • Check if server exists
  • time interval in c#
  • Extracting a sub-string in C#
  • C# - Programmatically Log-off and Log-on a user
  • c# array vs generic list
  • TCPClient in C# (Error)
  • How can I know if a file has been changed in .NET C#?
  • New to C# and trying to use a global variable
  • Convert RGB color to CMYK?
  • Tesseract.NET in C#
  • Is it possible to Update Sharepoint List Without "ID"?
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk