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

Individual colors for x-axis labels

1 Answer 287 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.
Sebastian
Top achievements
Rank 1
Sebastian asked on 06 Jun 2013, 03:28 PM
I have a RadCartesianChart with several stacked categorical BarSeries. I want to have indivual (self-defined) colors for every x-axis label, i.e. assign a color to every category. How can I to this?

<telerik:RadCartesianChart Width="420" Height="380"
                           Palette="{StaticResource BarsPalette}">
    <telerik:RadCartesianChart.HorizontalAxis>
        <telerik:CategoricalAxis LabelFitMode="MultiLine" />
    </telerik:RadCartesianChart.HorizontalAxis>
 
    <telerik:RadCartesianChart.VerticalAxis>
        <telerik:LinearAxis MajorStep="5" Maximum="30" />
    </telerik:RadCartesianChart.VerticalAxis>
 
    <telerik:RadCartesianChart.Grid>
        <telerik:CartesianChartGrid MajorLinesVisibility="Y" />
    </telerik:RadCartesianChart.Grid>
 
    <telerik:BarSeries ItemsSource="{Binding Path=ViewModel.Items1}"
                       CombineMode="Stack" ShowLabels="True">
        <telerik:BarSeries.CategoryBinding>
            <telerik:PropertyNameDataPointBinding PropertyName="Category" />
        </telerik:BarSeries.CategoryBinding>
        <telerik:BarSeries.ValueBinding>
            <telerik:PropertyNameDataPointBinding PropertyName="Value" />
        </telerik:BarSeries.ValueBinding>
 
        <telerik:BarSeries.LabelDefinitions>
            <telerik:ChartSeriesLabelDefinition HorizontalAlignment="Center"
                                                VerticalAlignment="Center">
                <telerik:ChartSeriesLabelDefinition.Template>
                    <DataTemplate>
                        <TextBlock Text="{Binding DataItem.Label}" />
                    </DataTemplate>
                </telerik:ChartSeriesLabelDefinition.Template>
            </telerik:ChartSeriesLabelDefinition>
        </telerik:BarSeries.LabelDefinitions>
    </telerik:BarSeries>
 
    <!-- etc. -->
    
</telerik:RadCartesianChart>

1 Answer, 1 is accepted

Sort by
0
Ivaylo Gergov
Telerik team
answered on 07 Jun 2013, 02:54 PM
Hello Sebastian,

Thank you for contacting us.

For this scenario, you can use the CategoricalAxis.LabelTemplate property to define a DataTemplate for the labels of the categorical axis. Then you can use an IValueConverter implementation to return different colors for each label. For your convenience, I have attached a runnable project that demonstrates this approach.

Let me know if this helps.

 

Regards,
Ivaylo Gergov
Telerik
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
Tags
Chart for XAML
Asked by
Sebastian
Top achievements
Rank 1
Answers by
Ivaylo Gergov
Telerik team
Share this question
or