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

Multiple colors for BarSeries

1 Answer 156 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 10 Aug 2012, 09:45 AM
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

1 Answer, 1 is accepted

Sort by
0
Evgenia
Telerik team
answered on 10 Aug 2012, 02:54 PM
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.

Tags
ChartView
Asked by
David
Top achievements
Rank 1
Answers by
Evgenia
Telerik team
Share this question
or