Multiple colors for BarSeries

2 posts, 0 answers
  1. David
    David avatar
    2 posts
    Member since:
    Aug 2011

    Posted 10 Aug 2012 Link to this post

    Hey,

    I want to use mutiple colors for one BarSeries in a RadCartesianChart.
    Do I really have to create a DataTemplate / PointTemplate for every color I want to use?

    Since there are about 20 colors I want to support, this would really look ugly in XAML.
    Is there any other way?

    Thanks and best regards

    David
  2. Evgenia
    Admin
    Evgenia avatar
    1406 posts

    Posted 10 Aug 2012 Link to this post

    Hello David,

     You can achieve this by using a single PointTemplate where the Fill of the Rectangle in it is bound to a Brush property of your business object. For instance:

    <telerik:RadCartesianChart x:Name="RadChartView1">
        <telerik:RadCartesianChart.HorizontalAxis>
            <telerik:CategoricalAxis/>
        </telerik:RadCartesianChart.HorizontalAxis>
        <telerik:RadCartesianChart.VerticalAxis>
            <telerik:LinearAxis/>
        </telerik:RadCartesianChart.VerticalAxis>
        <telerik:BarSeries ValueBinding="Value" ItemsSource="{Binding Data}"  >
            <telerik:BarSeries.PointTemplate>
                <DataTemplate>
                    <Rectangle Fill="{Binding DataItem.Color}"/>
                </DataTemplate>
            </telerik:BarSeries.PointTemplate>
        </telerik:BarSeries>
    </telerik:RadCartesianChart>

    Color is a property of type Brush, just like Value , so that it is specific for each DataItem. You may review the sample I prepared and attached to demonstrate what I mean. 

    All the best,
    Evgenia
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. DevCraft banner
Back to Top