Trying to set height on RadCartesianChart Bars

2 posts, 0 answers
  1. mike
    mike avatar
    9 posts
    Member since:
    May 2015

    Posted 17 Mar Link to this post

    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>



  2. Dinko
    Admin
    Dinko avatar
    201 posts

    Posted 22 Mar Link to this post

    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.
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top