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

Trying to set height on RadCartesianChart Bars

1 Answer 59 Views
Chart
This is a migrated thread and some comments may be shown as answers.
mike
Top achievements
Rank 1
mike asked on 17 Mar 2016, 08:05 PM

Hello:

We are unable to vary the height of the bar series even though the below property is given properly. The bar series height and width gets adjusted by itself.
The objective is the height of the Chart should remain same as well as the bar inside of it. When only one bar for example, the width of the bar should not auto adjust to be fat. 

  <telerik:RadCartesianChart Palette="Windows8"
                                           Grid.Row="1"
                                           Grid.Column="0"
                                           Grid.ColumnSpan="2"

                                           Margin="0,0,0,-205">
                    <telerik:RadCartesianChart.HorizontalAxis>
                        <telerik:LinearAxis Title="Days" />
                    </telerik:RadCartesianChart.HorizontalAxis>
                    <telerik:RadCartesianChart.VerticalAxis>
                        <telerik:CategoricalAxis />
                    </telerik:RadCartesianChart.VerticalAxis>
                    <telerik:RadCartesianChart.Series>
                        <telerik:BarSeries PaletteMode="DataPoint"
                                           ShowLabels="True"
                                           ItemsSource="{Binding LstRunningBatch}"
                                           CategoryBinding="BatchId"

                                           MinWidth="10"
                                           Width="15"
                                           MaxWidth="20"

                                           MinHeight="10"
                                           Height="150"
                                           MaxHeight="20"

                                           ValueBinding="TotalDays">
                        </telerik:BarSeries>
                    </telerik:RadCartesianChart.Series>
                </telerik:RadCartesianChart>



1 Answer, 1 is accepted

Sort by
0
Dinko
Telerik team
answered on 22 Mar 2016, 03:06 PM
Hello Mike,

Thank you for the provided information.

You can set the MaxHeight property of the bars by creating a custom DataTemplate and set it to the PointTemplate property of the BarSeries.
<telerik:BarSeries.PointTemplate>
<DataTemplate>
<Rectangle MaxHeight="30"
                Fill="{Binding Converter={StaticResource DataPointToBrushConverter}}"/>
</DataTemplate>
</telerik:BarSeries.PointTemplate>
Keep in mind that when you are using PointTemplate to customize the bar series, the Palette colors will not apply to the bars. In this case you can use an IValueConverter to get the fill color from the Palette and set it to the elements in the template. Note that, the DataContext passed to the PointTemplate is an object of type DataPoint which you can bind with the converter.  For your convenience, we have created a sample project where you can see how to implement this approach.

Please, give this project a try and let us know if this works for you.

Regards,
Dinko
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
Chart
Asked by
mike
Top achievements
Rank 1
Answers by
Dinko
Telerik team
Share this question
or