This is a migrated thread and some comments may be shown as answers.

[Solved] Dynamic series with random colors

3 Answers 333 Views
Chart for XAML
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Yasir
Top achievements
Rank 1
Yasir asked on 30 Oct 2013, 10:50 AM
Hi,

How can I change the color of dynamically generated series? Is there any way to achieve this through code behind.

Thanks

3 Answers, 1 is accepted

Sort by
0
Rosy Topchiyska
Telerik team
answered on 30 Oct 2013, 02:17 PM

Hello Yasir,

Thank you for the question.

You can take a look at this article from our online documentation that demonstrates how to create a custom palette. By default the palette applies on a per series basis.

If you use BarSeries and you want to apply a palette on a per data point basis, you have to set the BarSeries.PaletteMode property to DataPoint.

You may also use the PaletteIndex property of the ChartSeries to further customize the way the colors of the palette apply to the series. This property specifies the index of the color in the palette that will be used by the series.

I hope this was useful and do not hesitate to contact us if you have further questions.

Regards,
Rositsa Topchiyska
Telerik

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Rosy Topchiyska
Telerik team
answered on 31 Oct 2013, 11:37 AM

Hi Yasir,

In addition to my previous answer I have two more suggestions:

  1. If you have point type series:
    Through the Style property of the generated series you can set the PointTemplate property and via a value converter you can generate a color that depends on the specific data point and series. In the converter you will receive a CategoricalDataPoint/ScatterDataPoint/OhlcDataPoint as a context depending on the series type. Here is an example:

    <telerikChart:ChartSeriesProvider.SeriesDescrtiptors>
        <telerikChart:CategoricalSeriesDescriptor ValuePath="Value" CategoryPath="Category">
            <telerikChart:CategoricalSeriesDescriptor.Style>
                <Style TargetType="telerikChart:BarSeries">
                    <Setter Property="CombineMode" Value="Cluster"/>
                    <Setter Property="PointTemplate">
                        <Setter.Value>
                            <DataTemplate>
                                <Rectangle Fill="{Binding Converter={StaticResource converter}}" Margin="2,0,2,0"/>
                            </DataTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </telerikChart:CategoricalSeriesDescriptor.Style>
        </telerikChart:CategoricalSeriesDescriptor>
    </telerikChart:ChartSeriesProvider.SeriesDescriptors>
  2. If all previous suggestions do not fulfill your requirements, you can implement a custom series descriptor that inherits from the CategoricalSeriesDescriptor class and overrides the CreateInstanceCore method where you can set a style to the generated series. I have attached a sample project that demonstrates how to do that.

I hope this helps. Please, let us know if you have any other questions.

Regards,
Rositsa Topchiyska
Telerik

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.


0
Yasir
Top achievements
Rank 1
answered on 04 Nov 2013, 09:35 AM
Thanks Rositsa it working perfectly...
Tags
Chart for XAML
Asked by
Yasir
Top achievements
Rank 1
Answers by
Rosy Topchiyska
Telerik team
Yasir
Top achievements
Rank 1
Share this question
or