Click here to Skip to main content
15,899,000 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Chart control implemented in WPF using Visual studio Express for Desktop 2015 :-


C#
<ChartingToolkit:Chart Name="SimulationChart"
                                       IsTabStop="False"
                                       PlotAreaStyle="{StaticResource PlotAreaStyle}"
                                       BorderBrush="Transparent">
                    <ChartingToolkit:Chart.Template>
                        <ControlTemplate TargetType="ChartingToolkit:Chart">
                            <Border Background="{TemplateBinding Background}"
                                    BorderBrush="{TemplateBinding BorderBrush}"
                                    BorderThickness="{TemplateBinding BorderThickness}"
                                    Padding="{TemplateBinding Padding}">
                                <Grid>
                                    <chartingprimitives:EdgePanel x:Name="ChartArea" Style="{TemplateBinding ChartAreaStyle}">
                                        <Grid Canvas.ZIndex="-1" Style="{TemplateBinding PlotAreaStyle}" />
                                        <Border Canvas.ZIndex="20" BorderBrush="#FF919191" BorderThickness="1" />
                                    </chartingprimitives:EdgePanel>
                                </Grid>
                            </Border>
                        </ControlTemplate>
                    </ChartingToolkit:Chart.Template>
                </ChartingToolkit:Chart>


In the Following code, It sets same color (Red) for all columns. But I want to set different color for each column.


C#
private void ColorChartColumn()
    {          
            ColumnSeries CL = new ColumnSeries();      
            Style styleSeries = new Style { TargetType = typeof(Control) };
            styleSeries.Setters.Add(new Setter(Control.BackgroundProperty, System.Windows.Media.Brushes.Red));
            CL.DataPointStyle = styleSeries; 
            SimulationChart.Series.Add(CL);            
    }


What I have tried:

I have tried for many time, but till now, I am not getting answer for this.
Posted
Updated 13-Oct-19 21:08pm

1 solution

Please, follow this: Chart tweaking made easy [How to: Make four simple color/ToolTip changes with Silverlight/WPF Charting] - The blog of dlaa.me[^]

XML
<charting:Chart
    Title="Simple Palette Change">
    <charting:PieSeries
        ItemsSource="{Binding}"
        DependentValueBinding="{Binding Length}"
        IndependentValueBinding="{Binding}">
        <charting:PieSeries.StylePalette>
            <datavis:StylePalette>
                <Style TargetType="charting:PieDataPoint">
                    <Setter Property="Background" Value="Red"/>
                </Style>
                <Style TargetType="charting:PieDataPoint">
                    <Setter Property="Background" Value="Orange"/>
                </Style>
                <Style TargetType="charting:PieDataPoint">
                    <Setter Property="Background" Value="Green"/>
                </Style>
                <Style TargetType="charting:PieDataPoint">
                    <Setter Property="Background" Value="Blue"/>
                </Style>
            </datavis:StylePalette>
        </charting:PieSeries.StylePalette>
    </charting:PieSeries>
</charting:Chart>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900