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

Maximum bar width

1 Answer 70 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Steve
Top achievements
Rank 1
Steve asked on 04 Sep 2019, 05:08 AM

I don't remember where I got it, but I have some code:

 

Dim ColumnSeries As New Telerik.Windows.Controls.ChartView.BarSeries
ColumnSeries.PointTemplate = TryCast(Application.Current.TryFindResource("ColumnDataPointTemplate"), DataTemplate)

 

And in a resource dictionary: 

<DataTemplate x:Key="ColumnDataPointTemplate">
    <Rectangle Fill="{Binding Brush}" MaxWidth="40"/>
</DataTemplate>

 

It works fine for the Bar series but fails to display anything if I use the same resource for the point template of a RangeBarSeries. I found somewhere in a forum post I think to use DefaultVisualStyle and that does work to set the max width, BUT it does not center the bar on the category label tick.

<Style x:Key="RangeBarVisualStyle" TargetType="Border">
    <Setter Property="Background" Value="{Binding Brush}" />
    <Setter Property="BorderThickness" Value="0"/>
    <Setter Property="MaxWidth" Value="40"/>
    <Setter Property="HorizontalAlignment" Value="Center"/>
</Style>

It does the same thing if I use the visual style on the regular bar so I know it is not specific to the range bar.

In the attached picture, I am showing the bars with no point template or default visual style. The second is with a point template, and the last is with the default visual style.

I would like to make either of these work... I don't really care which one.

1 Answer, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 05 Sep 2019, 02:22 PM

Hello Steve,

My guess here would be that nothing is displayed with the PointTemplate approach, because the binding to the Fill property points to a none existing property (named Brush). The DataContext passed to the PointTemplate will be an object of type DataPoint. If you have a brush defined in your business models bound to the data points, you can use the DataItem property of DataPoint. Here is an example in code:

<Rectangle Fill="{Binding DataItem.MyBrush}" />

The DataItem property points to the business object behind the data point.

I hope this helps.

Regards,
Martin Ivanov
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
ChartView
Asked by
Steve
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or